Skip to content

Commit

Permalink
Fix empty api-keys option handling (#40)
Browse files Browse the repository at this point in the history
As strings.split("", ",") returns []string{""}, an empty api-keys option will cause apmsoak to throw "invalid api keys provided", effectively making api-keys a required option. Fix the handling to ignore empty api-keys.
  • Loading branch information
carsonip authored Sep 28, 2023
1 parent 3a7c8a2 commit e98c86d
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions cmd/apmsoak/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ type RunOptions struct {

func (opts *RunOptions) toRunnerConfig() (*soaktest.RunnerConfig, error) {
apiKeys := make(map[string]string)
pairs := strings.Split(opts.APIKeys, ",")
for _, pair := range pairs {
kv := strings.Split(pair, ":")
if len(kv) != 2 {
return nil, errors.New("invalid api keys provided. example: project_id:my_api_key")
if opts.APIKeys != "" {
pairs := strings.Split(opts.APIKeys, ",")
for _, pair := range pairs {
kv := strings.Split(pair, ":")
if len(kv) != 2 {
return nil, errors.New("invalid api keys provided. example: project_id:my_api_key")
}
apiKeys[kv[0]] = kv[1]
}
apiKeys[kv[0]] = kv[1]
}
return &soaktest.RunnerConfig{
Scenario: opts.Scenario,
Expand Down

0 comments on commit e98c86d

Please sign in to comment.