mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-10-10 04:44:02 +02:00
using testify instead of testing.T methods. (#143)
This commit is contained in:
@@ -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 {
|
||||
|
Reference in New Issue
Block a user