using testify instead of testing.T methods. (#143)

This commit is contained in:
K
2024-09-09 13:50:56 +03:30
committed by GitHub
parent b2692a2584
commit c91e7b9765
21 changed files with 473 additions and 643 deletions

View File

@ -4,19 +4,18 @@ import (
"context"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestEOSEMadness(t *testing.T) {
rl := mustRelayConnect(RELAY)
rl := mustRelayConnect(t, RELAY)
defer rl.Close()
sub, err := rl.Subscribe(context.Background(), Filters{
{Kinds: []int{KindTextNote}, Limit: 2},
})
if err != nil {
t.Errorf("subscription failed: %v", err)
return
}
assert.NoError(t, err)
timeout := time.After(3 * time.Second)
n := 0
@ -25,15 +24,13 @@ func TestEOSEMadness(t *testing.T) {
for {
select {
case event := <-sub.Events:
if event == nil {
t.Fatalf("event is nil: %v", event)
}
assert.NotNil(t, event)
n++
case <-sub.EndOfStoredEvents:
e++
if e > 1 {
t.Fatalf("eose infinite loop")
}
assert.Condition(t, func() (success bool) {
return !(e > 1)
}, "eose infinite loop")
continue
case <-rl.Context().Done():
t.Fatalf("connection closed: %v", rl.Context().Err())
@ -43,10 +40,8 @@ func TestEOSEMadness(t *testing.T) {
}
end:
if e != 1 {
t.Fatalf("didn't get an eose")
}
if n < 2 {
t.Fatalf("didn't get events")
}
assert.Equal(t, 1, e)
assert.Condition(t, func() (success bool) {
return n >= 2
})
}