-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Replace fatal with panic * Add nolint to non-even number of args
- Loading branch information
1 parent
744dd76
commit 48b1258
Showing
2 changed files
with
45 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package spcontext | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/franela/goblin" | ||
"github.com/onsi/gomega" | ||
) | ||
|
||
func TestFieldsWith(t *testing.T) { | ||
g := goblin.Goblin(t) | ||
gomega.RegisterFailHandler(func(m string, _ ...int) { g.Fail(m) }) | ||
|
||
g.Describe("Happy path", func() { | ||
f := &Fields{} | ||
newFields := f.With("test", 1, "test2", 2) | ||
g.It("empty base fields", func() { | ||
gomega.Expect(f.EvaluateFields()).To(gomega.Equal([]any(nil))) | ||
}) | ||
g.It("non empty new fields", func() { | ||
gomega.Expect(newFields.EvaluateFields()).To(gomega.Equal([]any{"test", 1, "test2", 2})) | ||
}) | ||
}) | ||
g.Describe("odd number of fields", func() { | ||
f := &Fields{} | ||
g.It("odd number of fields", func() { | ||
gomega.Expect(func() { | ||
f.With("test", 1, "test2") //nolint:staticcheck // negative test case | ||
}).To(gomega.PanicWith("invalid Fields.With call: odd number of arguments")) | ||
}) | ||
}) | ||
g.Describe("key is not string", func() { | ||
f := &Fields{} | ||
g.It("odd number of fields", func() { | ||
gomega.Expect(func() { | ||
f.With("test", 1, 3, 2) | ||
}).To(gomega.PanicWith("invalid Fields.With call: non-string log field key: 3")) | ||
}) | ||
}) | ||
|
||
} |