Skip to content

Commit

Permalink
chore: update KVs to read KV and KVs provided as inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
jsteenb2 committed Jul 6, 2024
1 parent d586353 commit 07bb819
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ func TestV(t *testing.T) {

eqV(t, err, "str", "wrapped")
})

t.Run("when provided KVs should incorporate them as they are without key mapping", func(t *testing.T) {
err := errors.New("simple msg", errors.KVs(errors.KVs("unspread", "vals"), errors.KV{K: "indiv", V: "1"}))

eqV(t, err, "unspread", "vals")
eqV(t, err, "indiv", "1")
})
}

func eq[T comparable](t *testing.T, want, got T) bool {
Expand Down
8 changes: 8 additions & 0 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ func KVs(fields ...any) []KV {
for i := 0; i < len(fields); i += 2 {
var kv KV
switch t := fields[i].(type) {
case []KV:
out = append(out, t...)
i--
continue
case KV:
out = append(out, t)
i--
continue
case string:
kv.K = t
case fmt.Stringer:
Expand Down

0 comments on commit 07bb819

Please sign in to comment.