Skip to content

Commit

Permalink
Update e2e tests to test toxicity
Browse files Browse the repository at this point in the history
  • Loading branch information
miry committed Sep 17, 2021
1 parent bc4e330 commit d062d0d
Showing 1 changed file with 35 additions and 24 deletions.
59 changes: 35 additions & 24 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,16 @@ var toxicDescription = `
average_size=<bytes>,size_variation=<bytes>,delay=<microseconds>
toxic add:
usage: toxiproxy-cli toxic add --type <toxicType> --toxicName <toxicName> \
--attribute <key=value> [--downstream|--upstream] <proxyName>
usage: toxiproxy-cli toxic add --type <toxicType> [--downstream|--upstream] \
--toxicName <toxicName> --toxicity <toxicity> \
--attribute <key=value> [--attribute <key2=value2>] <proxyName>\
example: toxiproxy-cli toxic add -t latency -n myToxic -a latency=100 -a jitter=50 myProxy
toxic update:
usage: toxiproxy-cli toxic update --toxicName <toxicName> \
--attribute <key1=value1> --attribute <key2=value2> <proxyName>
--attribute <key1=value1> [--attribute <key2=value2>] <proxyName>
example: toxiproxy-cli toxic update -n myToxic -a jitter=25 myProxy
Expand Down Expand Up @@ -179,9 +181,10 @@ func cliToxiAddSubCommand() *cli.Command {
Usage: "type of toxic",
},
&cli.StringFlag{
Name: "toxicity",
Aliases: []string{"tox"},
Usage: "toxicity of toxic",
Name: "toxicity",
Aliases: []string{"tox"},
Usage: "toxicity of toxic should be a float between 0 and 1",
DefaultText: "1.0",
},
&cli.StringSliceFlag{
Name: "attribute",
Expand Down Expand Up @@ -218,9 +221,10 @@ func cliToxiUpdateSubCommand() *cli.Command {
Usage: "name of the toxic",
},
&cli.StringFlag{
Name: "toxicity",
Aliases: []string{"tox"},
Usage: "toxicity of toxic",
Name: "toxicity",
Aliases: []string{"tox"},
Usage: "toxicity of toxic should be a float between 0 and 1",
DefaultText: "1.0",
},
&cli.StringSliceFlag{
Name: "attribute",
Expand Down Expand Up @@ -443,15 +447,28 @@ func parseToxicity(c *cli.Context, defaultToxicity float32) (float32, error) {
return toxicity, nil
}

func parseAddToxicParams(c *cli.Context) (*toxiproxy.ToxicOptions, error) {
proxyName := c.Args().First()
func parseToxicCommonParams(context *cli.Context) (*toxiproxy.ToxicOptions, error) {
proxyName := context.Args().First()
if proxyName == "" {
cli.ShowSubcommandHelp(c)
cli.ShowSubcommandHelp(context)
return nil, errorf("Proxy name is missing.\n")
}

toxicName := c.String("toxicName")
toxicType, err := getArgOrFail(c, "type")
toxicName := context.String("toxicName")

return &toxiproxy.ToxicOptions{
ProxyName: proxyName,
ToxicName: toxicName,
}, nil
}

func parseAddToxicParams(c *cli.Context) (*toxiproxy.ToxicOptions, error) {
result, err := parseToxicCommonParams(c)
if err != nil {
return nil, err
}

result.ToxicType, err = getArgOrFail(c, "type")
if err != nil {
return nil, err
}
Expand All @@ -466,22 +483,16 @@ func parseAddToxicParams(c *cli.Context) (*toxiproxy.ToxicOptions, error) {
if upstream {
stream = "upstream"
}
result.Stream = stream

toxicity, err := parseToxicity(c, 1.0)
result.Toxicity, err = parseToxicity(c, 1.0)
if err != nil {
return nil, err
}

attributes := parseAttributes(c, "attribute")
result.Attributes = parseAttributes(c, "attribute")

return &toxiproxy.ToxicOptions{
ProxyName: proxyName,
ToxicName: toxicName,
ToxicType: toxicType,
Toxicity: toxicity,
Attributes: attributes,
Stream: stream,
}, nil
return result, nil
}

func addToxic(c *cli.Context, t *toxiproxy.Client) error {
Expand Down

0 comments on commit d062d0d

Please sign in to comment.