frostfs-node/cmd/frostfs-adm/internal/modules/morph/frostfsid_util_test.go
Evgenii Stratonikov f1db468d48
All checks were successful
Vulncheck / Vulncheck (pull_request) Successful in 1m28s
DCO action / DCO (pull_request) Successful in 3m9s
Build / Build Components (1.21) (pull_request) Successful in 4m15s
Build / Build Components (1.20) (pull_request) Successful in 4m35s
Tests and linters / Staticcheck (pull_request) Successful in 4m58s
Tests and linters / Tests (1.20) (pull_request) Successful in 6m48s
Tests and linters / Tests (1.21) (pull_request) Successful in 7m6s
Tests and linters / Lint (pull_request) Successful in 7m25s
Tests and linters / Tests with -race (pull_request) Successful in 7m9s
[#840] adm: Update FrostFS ID deploy arguments
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
2023-12-04 17:39:41 +03:00

53 lines
1.2 KiB
Go

package morph
import (
"encoding/hex"
"testing"
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
"github.com/spf13/viper"
"github.com/stretchr/testify/require"
)
func TestFrostfsIDConfig(t *testing.T) {
pks := make([]*keys.PrivateKey, 4)
for i := range pks {
pk, err := keys.NewPrivateKey()
require.NoError(t, err)
pks[i] = pk
}
fmts := []string{
pks[0].GetScriptHash().StringLE(),
address.Uint160ToString(pks[1].GetScriptHash()),
hex.EncodeToString(pks[2].PublicKey().UncompressedBytes()),
hex.EncodeToString(pks[3].PublicKey().Bytes()),
}
for i := range fmts {
v := viper.New()
v.Set("frostfsid.admin", fmts[i])
actual, found, err := getFrostfsIDAdmin(v)
require.NoError(t, err)
require.True(t, found)
require.Equal(t, pks[i].GetScriptHash(), actual)
}
t.Run("bad key", func(t *testing.T) {
v := viper.New()
v.Set("frostfsid.admin", "abc")
_, found, err := getFrostfsIDAdmin(v)
require.Error(t, err)
require.True(t, found)
})
t.Run("missing key", func(t *testing.T) {
v := viper.New()
_, found, err := getFrostfsIDAdmin(v)
require.NoError(t, err)
require.False(t, found)
})
}