Skip to content

Commit

Permalink
Drop String, leave only Strings
Browse files Browse the repository at this point in the history
  • Loading branch information
mstoykov committed Aug 30, 2024
1 parent 269cb59 commit 92c53db
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 37 deletions.
14 changes: 8 additions & 6 deletions cmd/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,17 @@ func createReport(
}
u.Strings("outputs", o)
}

u.String("k6_version", consts.Version)
execState := execScheduler.GetState()
u.Uint64("vus_max", uint64(execState.GetInitializedVUsCount()))
u.Uint64("iterations", execState.GetFullIterationCount())
u.String("duration", execState.GetCurrentTestRunDuration().String())
u.String("goos", runtime.GOOS)
u.String("goarch", runtime.GOARCH)
return u.Map()
m := u.Map()

m["k6_version"] = consts.Version
m["duration"] = execState.GetCurrentTestRunDuration().String()
m["goos"] = runtime.GOOS
m["goarch"] = runtime.GOARCH

return m
}

func reportUsage(ctx context.Context, execScheduler *execution.Scheduler, test *loadedAndConfiguredTest) error {
Expand Down
2 changes: 1 addition & 1 deletion output/cloud/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ func (out *Output) startVersionedOutput() error {
}
var err error

out.usage.String("output.cloud.test_run_id", out.testRunID)
out.usage.Strings("cloud/test_run_id", out.testRunID)

// TODO: move here the creation of a new cloudapi.Client
// so in the case the config has been overwritten the client uses the correct
Expand Down
31 changes: 1 addition & 30 deletions usage/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,8 @@ func New() *Usage {
}
}

// String appends the provided value to a slice of strings that is the value.
// If called only a single time, the value will be just a string not a slice
func (u *Usage) String(k, v string) {
u.l.Lock()
defer u.l.Unlock()
oldV, ok := u.m[k]
if !ok {
u.m[k] = v
return
}
switch oldV := oldV.(type) {
case string:
u.m[k] = []string{oldV, v}
case []string:
u.m[k] = append(oldV, v)
default:
// TODO: error, panic?, nothing, log?
}
}

// Strings appends the provided value to a slice of strings that is the value.
// Unlike String it
// Appending to the slice if the key is already there.
func (u *Usage) Strings(k, v string) {
u.l.Lock()
defer u.l.Unlock()
Expand Down Expand Up @@ -109,15 +89,6 @@ func (u *Usage) Map() map[string]any {
default:
// TODO:panic? error?
}
case string:
switch i := keyLevel.(type) {
case string:
keyLevel = append([]string(nil), i, value)
case []string:
keyLevel = append(i, value) //nolint:gocritic // we assign to the final value
default:
// TODO:panic? error?
}
case []string:
switch i := keyLevel.(type) {
case []string:
Expand Down

0 comments on commit 92c53db

Please sign in to comment.