From a7b720911276c24fd1a2a92f5915e8381ffd401a Mon Sep 17 00:00:00 2001 From: Dmitry Kolupaev Date: Thu, 14 Mar 2024 18:39:14 +0400 Subject: [PATCH] add unit tests --- internal/app/app.go | 4 +-- internal/subscriber/subscriber_test.go | 40 ++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 internal/subscriber/subscriber_test.go diff --git a/internal/app/app.go b/internal/app/app.go index 93d91fdf..8317fb53 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -62,7 +62,7 @@ func NewDefaultSubscriber(cfg config.NeutronQueryRelayerConfig, logRegistry *nlo watchedMsgTypes = append(watchedMsgTypes, neutrontypes.InterchainQueryTypeTX) } - subscriber, err := relaysubscriber.NewSubscriber( + sub, err := relaysubscriber.NewSubscriber( &subscriber.SubscriberConfig{ RPCAddress: cfg.NeutronChain.RPCAddr, RESTAddress: cfg.NeutronChain.RESTAddr, @@ -77,7 +77,7 @@ func NewDefaultSubscriber(cfg config.NeutronQueryRelayerConfig, logRegistry *nlo return nil, fmt.Errorf("failed to create a NewSubscriber: %s", err) } - return subscriber, nil + return sub, nil } func NewDefaultTxSubmitChecker(cfg config.NeutronQueryRelayerConfig, logRegistry *nlogger.Registry, diff --git a/internal/subscriber/subscriber_test.go b/internal/subscriber/subscriber_test.go new file mode 100644 index 00000000..9a161615 --- /dev/null +++ b/internal/subscriber/subscriber_test.go @@ -0,0 +1,40 @@ +package subscriber_test + +import ( + "context" + "github.com/neutron-org/neutron-query-relayer/internal/subscriber" + neutrontypes "github.com/neutron-org/neutron/x/interchainqueries/types" + "github.com/stretchr/testify/require" + "go.uber.org/zap" + + "github.com/stretchr/testify/assert" + "testing" +) + +func TestDoneShouldEndSubscribe(t *testing.T) { + cfgLogger := zap.NewProductionConfig() + logger, err := cfgLogger.Build() + require.NoError(t, err) + + queriesTasksQueue := make(chan neutrontypes.RegisteredQuery, 100) + cfg := subscriber.SubscriberConfig{ + RPCAddress: "", + RESTAddress: "", + Timeout: 0, + ConnectionID: "", + WatchedTypes: nil, + Registry: nil, + } + s, err := subscriber.NewSubscriber(&cfg, logger) + assert.NoError(t, err) + + ctx, cancel := context.WithCancel(context.Background()) + + go func() { + // should terminate Subscribe() function + cancel() + }() + + err = s.Subscribe(ctx, queriesTasksQueue) + assert.Equal(t, err, nil) +}