Repository navigation
Add --disabled flag to toxiproxy-cli create - #792
Open
officialasishkumar wants to merge 1 commit into
Open
officialasishkumar wants to merge 1 commit into
officialasishkumar wants to merge 1 commit into
Conversation
The HTTP API and the clients can create a proxy that starts out disabled by sending `"enabled": false`, but `toxiproxy-cli create` always created an enabled proxy. Getting a disabled proxy from the CLI meant creating it and toggling it afterwards, which briefly binds the listen address and accepts connections in between. `toxiproxy-cli create --disabled` now sends `enabled: false` in the create request, so the server registers the proxy without starting its listener. It can be enabled later with `toxiproxy-cli toggle`. The CLI now builds the proxy with `NewProxy()` + `Save()`, which is what `Client.CreateProxy` does internally, so the request is unchanged when the flag is not set. The app construction is moved out of `main()` into `newApp()` so the command can be exercised in tests against an in-process API server.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The HTTP API and the clients can create a proxy that starts out disabled (
"enabled": false), buttoxiproxy-cli createalways created an enabled one. From the CLI you had to create the proxy and thentoggleit, which binds the listen address and accepts connections in between.Change
toxiproxy-cli creategets a--disabledflag. It sendsenabled: falsein the create request, so the server registers the proxy without starting its listener.toxiproxy-cli toggle <proxyName>enables it later.NewProxy()+Save(), which is whatClient.CreateProxydoes internally, so nothing changes when the flag isn't set. The only visible difference is that a failed create no longer repeats the word:Failed to create proxy: HTTP 409: proxy already existsinstead ofFailed to create proxy: create: HTTP 409: ....main()intonewApp()so the command can be tested.Tests
Added
cmd/cli/cli_test.go, the first test for the CLI. It runs the real app, including flag parsing and--host, against an in-process API server on anhttptestport. It checks thatcreatewithout the flag gives an enabled proxy whose listen address has been resolved, and thatcreate --disabledgives a disabled proxy that never bound its port. The disabled case fails if the flag is ignored.I also checked it by hand with the built binaries: after
create --disabledthe listen port refuses connections andlistshows the proxy asdisabled; aftertoggletraffic goes through.Fixes #156