MCPcopy Create free account
hub / github.com/TheThingsNetwork/lorawan-stack / TestAttributesError

Function TestAttributesError

pkg/errors/attributes_test.go:25–46  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

23)
24
25func TestAttributesError(t *testing.T) {
26 t.Parallel()
27 a := assertions.New(t)
28
29 errInvalidFoo := errors.DefineInvalidArgument("test_attributes_invalid_foo", "Invalid Foo: {foo}", "foo")
30
31 a.So(errInvalidFoo.Attributes(), should.BeEmpty)
32
33 a.So(func() { errInvalidFoo.WithAttributes("only_key") }, should.Panic) //nolint:errcheck
34
35 err1 := errInvalidFoo.WithAttributes("foo", "bar")
36 err2 := err1.WithAttributes("bar", "baz")
37
38 a.So(err1, should.HaveSameErrorDefinitionAs, errInvalidFoo)
39 a.So(errors.Attributes(err1), should.Resemble, map[string]any{"foo": "bar"})
40 a.So(errors.PublicAttributes(err1), should.Resemble, map[string]any{"foo": "bar"})
41
42 a.So(err2, should.HaveSameErrorDefinitionAs, err1)
43 a.So(err2, should.HaveSameErrorDefinitionAs, errInvalidFoo)
44 a.So(errors.Attributes(err2), should.Resemble, map[string]any{"foo": "bar", "bar": "baz"})
45 a.So(errors.PublicAttributes(err2), should.Resemble, map[string]any{"foo": "bar"})
46}
47
48func TestAttributes(t *testing.T) {
49 t.Parallel()

Callers

nothing calls this directly

Calls 6

DefineInvalidArgumentFunction · 0.92
AttributesFunction · 0.92
PublicAttributesFunction · 0.92
NewMethod · 0.65
AttributesMethod · 0.65
WithAttributesMethod · 0.45

Tested by

no test coverage detected