From 2dbe382b5f19c0c46115bd40f8d472c0e0cc6076 Mon Sep 17 00:00:00 2001 From: Dmitrii Stepanov Date: Tue, 25 Apr 2023 14:54:01 +0300 Subject: [PATCH] [#280] ir: Add state unit tests Signed-off-by: Dmitrii Stepanov --- pkg/innerring/state_test.go | 53 +++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 pkg/innerring/state_test.go diff --git a/pkg/innerring/state_test.go b/pkg/innerring/state_test.go new file mode 100644 index 000000000..fe09f8f2d --- /dev/null +++ b/pkg/innerring/state_test.go @@ -0,0 +1,53 @@ +package innerring + +import ( + "testing" + "time" + + "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client" + control "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/control/ir" + "github.com/nspcc-dev/neo-go/pkg/crypto/keys" + "github.com/stretchr/testify/require" +) + +func TestServerState(t *testing.T) { + keyStr := "03ff65b6ae79134a4dce9d0d39d3851e9bab4ee97abf86e81e1c5bbc50cd2826ae" + commiteeKeys, err := keys.NewPublicKeysFromStrings([]string{keyStr}) + require.NoError(t, err, "convert string to commitee public keys failed") + cf := &testCommiteeFetcher{ + keys: commiteeKeys, + } + + irKeys, err := keys.NewPublicKeysFromStrings([]string{keyStr}) + require.NoError(t, err, "convert string to IR public keys failed") + irf := &testIRFetcher{ + keys: irKeys, + } + + key, err := keys.NewPublicKeyFromString(keyStr) + require.NoError(t, err, "convert string to public key failed") + + require.NoError(t, err, "failed to create morph client") + srv := &Server{ + statusIndex: newInnerRingIndexer(cf, irf, key, time.Second), + morphClient: &client.Client{}, + } + + var epoch uint64 = 100 + srv.SetEpochCounter(epoch) + require.Equal(t, epoch, srv.EpochCounter(), "invalid epoch counter") + + var epochDuration uint64 = 15 + srv.SetEpochDuration(epochDuration) + require.Equal(t, epochDuration, srv.EpochDuration(), "invalid epoch duration") + + var healthStatus control.HealthStatus = control.HealthStatus_READY + srv.setHealthStatus(healthStatus) + require.Equal(t, healthStatus, srv.HealthStatus(), "invalid health status") + + require.True(t, srv.IsActive(), "invalid IsActive result") + require.True(t, srv.IsAlphabet(), "invalid IsAlphabet result") + require.Equal(t, 0, srv.InnerRingIndex(), "invalid IR index") + require.Equal(t, 1, srv.InnerRingSize(), "invalid IR index") + require.Equal(t, 0, srv.AlphabetIndex(), "invalid alphabet index") +}