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

@@ -6,20 +6,19 @@ import (
"sync/atomic"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
const RELAY = "wss://nos.lol"
// test if we can fetch a couple of random events
func TestSubscribeBasic(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.Fatalf("subscription failed: %v", err)
return
}
assert.NoError(t, err)
timeout := time.After(5 * time.Second)
n := 0
@@ -27,9 +26,7 @@ func TestSubscribeBasic(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:
goto end
@@ -43,34 +40,26 @@ func TestSubscribeBasic(t *testing.T) {
}
end:
if n != 2 {
t.Fatalf("expected 2 events, got %d", n)
}
assert.Equal(t, 2, n)
}
// test if we can do multiple nested subscriptions
func TestNestedSubscriptions(t *testing.T) {
rl := mustRelayConnect(RELAY)
rl := mustRelayConnect(t, RELAY)
defer rl.Close()
n := atomic.Uint32{}
// fetch 2 replies to a note
sub, err := rl.Subscribe(context.Background(), Filters{{Kinds: []int{KindTextNote}, Tags: TagMap{"e": []string{"0e34a74f8547e3b95d52a2543719b109fd0312aba144e2ef95cba043f42fe8c5"}}, Limit: 3}})
if err != nil {
t.Fatalf("subscription 1 failed: %v", err)
return
}
assert.NoError(t, err)
for {
select {
case event := <-sub.Events:
// now fetch author of this
sub, err := rl.Subscribe(context.Background(), Filters{{Kinds: []int{KindProfileMetadata}, Authors: []string{event.PubKey}, Limit: 1}})
if err != nil {
t.Fatalf("subscription 2 failed: %v", err)
return
}
assert.NoError(t, err)
for {
select {