IR unit tests #280

Merged
fyrchik merged 11 commits from dstepanov-yadro/frostfs-node:object-3607 into master 2023-05-02 08:48:09 +00:00
Showing only changes of commit fd0f07dd5e - Show all commits

View file

@ -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")
}