test: extend coverage with missing test

This commit is contained in:
Anthony Laibe 2021-11-10 10:46:11 +01:00
parent b81bd6ff30
commit 9f504b1150
5 changed files with 121 additions and 1 deletions

View File

@ -0,0 +1,31 @@
package protocol
import (
"testing"
"github.com/status-im/go-waku/waku/v2/protocol/pb"
"github.com/stretchr/testify/require"
)
func TestEnvelope(t *testing.T) {
e := NewEnvelope(
&pb.WakuMessage{ContentTopic: "ContentTopic"},
"test",
)
msg := e.Message()
require.Equal(t, "ContentTopic", msg.ContentTopic)
topic := e.PubsubTopic()
require.Equal(t, "test", topic)
hash := e.Hash()
require.Equal(
t,
[]uint8([]byte{0x2d, 0x84, 0x3d, 0x43, 0x77, 0x14, 0x4, 0xad, 0x64, 0x9d, 0x90, 0xd6, 0x5c, 0xc7, 0x3d, 0x8f, 0x21, 0x49, 0xa, 0xf1, 0x9c, 0x83, 0x88, 0x76, 0x51, 0xba, 0x6f, 0x34, 0x14, 0x78, 0x93, 0xd2}),
hash,
)
size := e.Size()
require.Equal(t, 14, size)
}

View File

@ -0,0 +1,32 @@
package filter
import (
"testing"
"github.com/status-im/go-waku/waku/v2/protocol"
"github.com/stretchr/testify/require"
)
func TestFilterMap(t *testing.T) {
fmap := NewFilterMap()
filter := Filter{
PeerID: "id",
Topic: "test",
ContentFilters: []string{"test"},
Chan: make(chan *protocol.Envelope),
}
fmap.Set("test", filter)
res := <-fmap.Items()
require.Equal(t, "test", res.Key)
item, ok := fmap.Get("test")
require.True(t, ok)
require.Equal(t, "test", item.Topic)
fmap.Delete("test")
_, ok = fmap.Get("test")
require.False(t, ok)
}

View File

@ -0,0 +1,37 @@
package lightpush
import (
"context"
"crypto/rand"
"testing"
"github.com/status-im/go-waku/tests"
"github.com/stretchr/testify/require"
)
func TestLightPushOption(t *testing.T) {
port, err := tests.FindFreePort(t, "", 5)
require.NoError(t, err)
host, err := tests.MakeHost(context.Background(), port, rand.Reader)
require.NoError(t, err)
options := []LightPushOption{
WithPeer("QmWLxGxG65CZ7vRj5oNXCJvbY9WkF9d9FxuJg8cg8Y7q3"),
WithAutomaticPeerSelection(host),
WithFastestPeerSelection(context.Background()),
WithRequestId([]byte("requestId")),
WithAutomaticRequestId(),
}
params := new(LightPushParameters)
params.host = host
for _, opt := range options {
opt(params)
}
require.Equal(t, host, params.host)
require.NotNil(t, params.selectedPeer)
require.NotNil(t, params.requestId)
}

View File

@ -0,0 +1,18 @@
package relay
import (
"testing"
waku_proto "github.com/status-im/go-waku/waku/v2/protocol"
"github.com/stretchr/testify/require"
)
func TestSubscription(t *testing.T) {
e := Subscription{
closed: false,
C: make(chan *waku_proto.Envelope, 10),
quit: make(chan struct{}),
}
e.Unsubscribe()
require.True(t, e.closed)
}

View File

@ -10,6 +10,8 @@ import (
func TestGetUnixEpochFrom(t *testing.T) {
loc := time.UTC
timestamp := GetUnixEpochFrom(time.Date(2019, 1, 1, 0, 0, 0, 0, loc))
require.Equal(t, float64(1546300800), timestamp)
timestamp = GetUnixEpoch()
require.NotNil(t, timestamp)
}