2021-11-10 09:46:11 +00:00
|
|
|
package lightpush
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"crypto/rand"
|
|
|
|
"testing"
|
|
|
|
|
2023-11-15 14:26:55 +00:00
|
|
|
"github.com/multiformats/go-multiaddr"
|
2021-11-10 09:46:11 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2022-11-09 19:53:01 +00:00
|
|
|
"github.com/waku-org/go-waku/tests"
|
|
|
|
"github.com/waku-org/go-waku/waku/v2/utils"
|
2021-11-10 09:46:11 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
2024-02-05 12:53:15 +00:00
|
|
|
options := []RequestOption{
|
2021-11-10 09:46:11 +00:00
|
|
|
WithPeer("QmWLxGxG65CZ7vRj5oNXCJvbY9WkF9d9FxuJg8cg8Y7q3"),
|
2022-08-15 17:13:45 +00:00
|
|
|
WithAutomaticPeerSelection(),
|
2023-10-16 16:42:01 +00:00
|
|
|
WithFastestPeerSelection(),
|
2023-07-19 16:25:35 +00:00
|
|
|
WithRequestID([]byte("requestID")),
|
|
|
|
WithAutomaticRequestID(),
|
2021-11-10 09:46:11 +00:00
|
|
|
}
|
|
|
|
|
2024-02-05 12:53:15 +00:00
|
|
|
params := new(lightPushRequestParameters)
|
2021-11-10 09:46:11 +00:00
|
|
|
params.host = host
|
2022-05-30 15:55:30 +00:00
|
|
|
params.log = utils.Logger()
|
2021-11-10 09:46:11 +00:00
|
|
|
|
|
|
|
for _, opt := range options {
|
2023-11-15 14:26:55 +00:00
|
|
|
err := opt(params)
|
|
|
|
require.NoError(t, err)
|
2021-11-10 09:46:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
require.Equal(t, host, params.host)
|
|
|
|
require.NotNil(t, params.selectedPeer)
|
2023-07-19 16:25:35 +00:00
|
|
|
require.NotNil(t, params.requestID)
|
2023-11-15 14:26:55 +00:00
|
|
|
|
|
|
|
maddr, err := multiaddr.NewMultiaddr("/ip4/127.0.0.1/tcp/12345/p2p/16Uiu2HAm8KUwGRruseAaEGD6xGg6XKrDo8Py5dwDoL9wUpCxawGy")
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2024-02-05 12:53:15 +00:00
|
|
|
options = []RequestOption{
|
2023-11-15 14:26:55 +00:00
|
|
|
WithPeer("16Uiu2HAm8KUwGRruseAaEGD6xGg6XKrDo8Py5dwDoL9wUpCxawGy"),
|
|
|
|
WithPeerAddr(maddr),
|
|
|
|
}
|
|
|
|
|
|
|
|
for idx, opt := range options {
|
|
|
|
err = opt(params)
|
|
|
|
if idx == 0 {
|
|
|
|
require.NoError(t, err)
|
|
|
|
} else {
|
|
|
|
require.Error(t, err)
|
|
|
|
}
|
|
|
|
}
|
2021-11-10 09:46:11 +00:00
|
|
|
}
|