test(event/stream): adopt testify to match existing lib style

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.
This commit is contained in:
Sebastian Norling
2026-05-21 14:11:46 +02:00
parent f679aab0d5
commit 4da4842f61
2 changed files with 17 additions and 31 deletions

View File

@@ -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)
}
}

View File

@@ -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))
}