MCPcopy
hub / github.com/nats-io/nats.go / TestNATSErrorIs

Function TestNATSErrorIs

micro/error_test.go:44–85  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

42}
43
44func TestNATSErrorIs(t *testing.T) {
45 natsErr1 := &NATSError{
46 Subject: "test.subject",
47 Description: "test description",
48 }
49
50 natsErr2 := &NATSError{
51 Subject: "test.subject",
52 Description: "test description",
53 }
54
55 natsErr3 := &NATSError{
56 Subject: "different.subject",
57 Description: "test description",
58 }
59
60 natsErr4 := &NATSError{
61 Subject: "test.subject",
62 Description: "different description",
63 }
64
65 // Test equality
66 if !errors.Is(natsErr1, natsErr2) {
67 t.Errorf("Is() = false, want true for equal errors")
68 }
69
70 // different subject
71 if errors.Is(natsErr1, natsErr3) {
72 t.Errorf("Is() = true, want false for different subjects")
73 }
74
75 // different description
76 if errors.Is(natsErr1, natsErr4) {
77 t.Errorf("Is() = true, want false for different descriptions")
78 }
79
80 // non NATSError
81 otherErr := errors.New("other error")
82 if errors.Is(natsErr1, otherErr) {
83 t.Errorf("Is() = true, want false for non-NATSError")
84 }
85}
86
87func TestNATSErrorWrapping(t *testing.T) {
88 // Test error chain

Callers

nothing calls this directly

Calls 2

ErrorfMethod · 0.80
IsMethod · 0.45

Tested by

no test coverage detected