Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix empty api-keys option handling #40

Merged
merged 2 commits into from
Sep 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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, ",")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thought: I wonder if we could use strings.Cut and get rid of the two ifs.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how that works to split by the : and eliminate the 2nd if. Also I think the current code's intention is very clear and shorter code isn't necessarily more readable.

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