Skip to content

Add --disabled flag to toxiproxy-cli create - #792

Open
officialasishkumar wants to merge 1 commit into
Shopify:mainfrom
officialasishkumar:feature/cli-create-disabled
Open

officialasishkumar wants to merge 1 commit into
Shopify:mainfrom
officialasishkumar:feature/cli-create-disabled

Conversation

@officialasishkumar

Copy link
Copy Markdown

The HTTP API and the clients can create a proxy that starts out disabled ("enabled": false), but toxiproxy-cli create always created an enabled one. From the CLI you had to create the proxy and then toggle it, which binds the listen address and accepts connections in between.

Change

  • toxiproxy-cli create gets a --disabled flag. It sends enabled: false in the create request, so the server registers the proxy without starting its listener. toxiproxy-cli toggle <proxyName> enables it later.
  • The CLI now builds the request with NewProxy() + Save(), which is what Client.CreateProxy does 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 exists instead of Failed to create proxy: create: HTTP 409: ....
  • The app setup moves out of main() into newApp() so the command can be tested.
  • Added a README note and a CHANGELOG entry.

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 an httptest port. It checks that create without the flag gives an enabled proxy whose listen address has been resolved, and that create --disabled gives 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 --disabled the listen port refuses connections and list shows the proxy as disabled; after toggle traffic goes through.

Fixes #156

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add -disabled flag for new proxies in CLI

1 participant