From ae05c68cef2497510a5b423074c5a92b250f9b65 Mon Sep 17 00:00:00 2001 From: Sergey Date: Fri, 26 Jul 2024 14:11:02 +0300 Subject: [PATCH] chore: add nodes manager test --- pkg/nodes_manager/nodes_manager_test.go | 49 +++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 pkg/nodes_manager/nodes_manager_test.go diff --git a/pkg/nodes_manager/nodes_manager_test.go b/pkg/nodes_manager/nodes_manager_test.go new file mode 100644 index 0000000..bb596c7 --- /dev/null +++ b/pkg/nodes_manager/nodes_manager_test.go @@ -0,0 +1,49 @@ +package nodes_manager + +import ( + configPkg "main/pkg/config" + "main/pkg/config/types" + loggerPkg "main/pkg/logger" + "main/pkg/metrics" + types2 "main/pkg/types" + "testing" + + "github.com/jarcoal/httpmock" + "github.com/stretchr/testify/require" +) + +//nolint:paralleltest // disabled due to httpmock usage +func TestNodesManagerReceive(t *testing.T) { + httpmock.Activate() + defer httpmock.DeactivateAndReset() + + config := &configPkg.AppConfig{ + Chains: types.Chains{ + {Name: "chain", TendermintNodes: []string{"example"}}, + }, + Metrics: configPkg.MetricsConfig{Enabled: false}, + } + + logger := loggerPkg.GetNopLogger() + metricsManager := metrics.NewManager(logger, config.Metrics) + nodesManager := NewNodesManager(logger, config, metricsManager) + + go nodesManager.Listen() + defer nodesManager.Stop() + + reportable := &types2.Tx{Hash: types.Link{Value: "123"}} + + nodesManager.Nodes["chain"][0].Channel <- types2.Report{ + Chain: config.Chains[0], + Reportable: reportable, + } + + received := <-nodesManager.Channel + + require.Equal(t, "123", received.Reportable.GetHash()) + + nodesManager.Nodes["chain"][0].Channel <- types2.Report{ + Chain: config.Chains[0], + Reportable: reportable, + } +}