Skip to content

Commit

Permalink
feat: dereference pointers of context when necessary, to make logs mo…
Browse files Browse the repository at this point in the history
…re readable
  • Loading branch information
samber committed Jun 3, 2024
1 parent 55e40f1 commit 2a46495
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions kv_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package oops

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestDereferencePointers(t *testing.T) {
is := assert.New(t)

ptr := func(v string) *string { return &v }

err := With("hello", "world").Errorf(assert.AnError.Error()).(OopsError)
is.EqualValues(map[string]any{"hello": "world"}, err.Context())

err = With("hello", ptr("world")).Errorf(assert.AnError.Error()).(OopsError)
is.EqualValues(map[string]any{"hello": "world"}, err.Context())

err = With("hello", nil).Errorf(assert.AnError.Error()).(OopsError)
is.EqualValues(map[string]any{"hello": nil}, err.Context())
}

0 comments on commit 2a46495

Please sign in to comment.