From 4da4842f61dc195b5165bdf36e0910a42cb2b1d4 Mon Sep 17 00:00:00 2001 From: Sebastian Norling <1932208+Bazze@users.noreply.github.com> Date: Thu, 21 May 2026 14:11:46 +0200 Subject: [PATCH] test(event/stream): adopt testify to match existing lib style MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The rest of github.com/kerberos-io/onvif uses stretchr/testify (assert, require) consistently — Device_test.go, event/type_test.go, media2/types_test.go, ws-discovery/networking_test.go. Migrate the two new test files in event/stream from stdlib t.Errorf to the same testify convention so the package fits in without local style variation. No production-code change; no behaviour change. --- event/stream/topics_test.go | 18 ++++++++---------- event/stream/types_test.go | 30 +++++++++--------------------- 2 files changed, 17 insertions(+), 31 deletions(-) diff --git a/event/stream/topics_test.go b/event/stream/topics_test.go index 58a96de..482dad2 100644 --- a/event/stream/topics_test.go +++ b/event/stream/topics_test.go @@ -1,6 +1,10 @@ package stream -import "testing" +import ( + "testing" + + "github.com/stretchr/testify/assert" +) func TestClassifyTopic(t *testing.T) { tests := []struct { @@ -88,9 +92,7 @@ func TestClassifyTopic(t *testing.T) { } for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { - if got := Classify(tc.topic); got != tc.want { - t.Errorf("Classify(%q) = %v, want %v", tc.topic, got, tc.want) - } + assert.Equal(t, tc.want, Classify(tc.topic), "topic=%q", tc.topic) }) } } @@ -98,9 +100,7 @@ func TestClassifyTopic(t *testing.T) { func TestClassifyIsCaseSensitive(t *testing.T) { // ONVIF topic identifiers are case-sensitive per the spec; a // lowercased topic must not match a capitalised pattern. - if got := Classify("tns1:videosource/motionalarm"); got != KindUnknown { - t.Errorf("Classify lowercase = %v, want KindUnknown (topics are case-sensitive)", got) - } + assert.Equal(t, KindUnknown, Classify("tns1:videosource/motionalarm")) } func TestCanonicalizeTopicStripsNamespaces(t *testing.T) { @@ -114,8 +114,6 @@ func TestCanonicalizeTopicStripsNamespaces(t *testing.T) { {"", ""}, } for _, tc := range tests { - if got := canonicalizeTopic(tc.in); got != tc.want { - t.Errorf("canonicalizeTopic(%q) = %q, want %q", tc.in, got, tc.want) - } + assert.Equal(t, tc.want, canonicalizeTopic(tc.in), "input=%q", tc.in) } } diff --git a/event/stream/types_test.go b/event/stream/types_test.go index 45d4069..d6e8313 100644 --- a/event/stream/types_test.go +++ b/event/stream/types_test.go @@ -3,6 +3,8 @@ package stream import ( "testing" "time" + + "github.com/stretchr/testify/assert" ) func TestEventKindString(t *testing.T) { @@ -20,9 +22,7 @@ func TestEventKindString(t *testing.T) { {EventKind(255), "EventKind(255)"}, } for _, tc := range tests { - if got := tc.kind.String(); got != tc.want { - t.Errorf("EventKind(%d).String() = %q, want %q", tc.kind, got, tc.want) - } + assert.Equal(t, tc.want, tc.kind.String()) } } @@ -37,9 +37,7 @@ func TestEventStateString(t *testing.T) { {EventState(255), "EventState(255)"}, } for _, tc := range tests { - if got := tc.state.String(); got != tc.want { - t.Errorf("EventState(%d).String() = %q, want %q", tc.state, got, tc.want) - } + assert.Equal(t, tc.want, tc.state.String()) } } @@ -55,29 +53,19 @@ func TestPropertyOperationString(t *testing.T) { {PropertyOperation(255), "PropertyOperation(255)"}, } for _, tc := range tests { - if got := tc.op.String(); got != tc.want { - t.Errorf("PropertyOperation(%d).String() = %q, want %q", tc.op, got, tc.want) - } + assert.Equal(t, tc.want, tc.op.String()) } } func TestEventZeroValue(t *testing.T) { var e Event - if e.Kind != KindUnknown { - t.Errorf("zero Event.Kind = %v, want KindUnknown", e.Kind) - } - if e.State != StateUnknown { - t.Errorf("zero Event.State = %v, want StateUnknown", e.State) - } - if !e.Timestamp.IsZero() { - t.Errorf("zero Event.Timestamp = %v, want zero time", e.Timestamp) - } + assert.Equal(t, KindUnknown, e.Kind) + assert.Equal(t, StateUnknown, e.State) + assert.True(t, e.Timestamp.IsZero()) } func TestEventTimestampPreserved(t *testing.T) { now := time.Now() e := Event{Timestamp: now} - if !e.Timestamp.Equal(now) { - t.Errorf("Event.Timestamp = %v, want %v", e.Timestamp, now) - } + assert.True(t, e.Timestamp.Equal(now)) }