diff --git a/event/event_test.go b/event/event_test.go index 2f2126c..bd37852 100644 --- a/event/event_test.go +++ b/event/event_test.go @@ -38,7 +38,7 @@ func TestReceive(t *testing.T) { // We must capture the event assert.NoError(t, err) - assert.True(t, len(data) >= 0) + assert.GreaterOrEqual(t, len(data), 1) for _, d := range data { assert.NotEqual(t, string(d.Data), "") assert.NotEqual(t, string(d.Type), "") @@ -80,7 +80,7 @@ func TestSubscribe(t *testing.T) { assert.Error(t, err) assert.True(t, errors.Is(err, context.Canceled)) - assert.True(t, elapsed >= 100*time.Millisecond) + assert.GreaterOrEqual(t, elapsed, 100*time.Millisecond) } func TestProcessEvent(t *testing.T) { diff --git a/internal/assert/assert.go b/internal/assert/assert.go index b6768d6..c766b94 100644 --- a/internal/assert/assert.go +++ b/internal/assert/assert.go @@ -1,6 +1,7 @@ package assert import ( + "cmp" "reflect" "testing" ) @@ -71,3 +72,31 @@ func True(t *testing.T, got bool) { t.Errorf("got: %#v, want: true", got) } } + +func GreaterOrEqual[T cmp.Ordered](t *testing.T, got, want T) { + t.Helper() + if got < want { + t.Errorf("got: %#v, want: >=%#v", got, want) + } +} + +func Greater[T cmp.Ordered](t *testing.T, got, want T) { + t.Helper() + if got <= want { + t.Errorf("got: %#v, want: >%#v", got, want) + } +} + +func LesserOrEqual[T cmp.Ordered](t *testing.T, got, want T) { + t.Helper() + if got > want { + t.Errorf("got: %#v, want: <=%#v", got, want) + } +} + +func Lesser[T cmp.Ordered](t *testing.T, got, want T) { + t.Helper() + if got >= want { + t.Errorf("got: %#v, want: <%#v", got, want) + } +}