From c87c3d3721c988788efcdec1ee353d86ebabfc58 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Mon, 24 Oct 2022 14:38:55 +0300 Subject: [PATCH] [#1959] neofs-adm: Refactor tests Make it easier to test both common deployment scenarios. Signed-off-by: Evgenii Stratonikov --- .../internal/modules/morph/generate_test.go | 26 +++++++--------- .../internal/modules/morph/initialize_test.go | 30 +++++++++++++------ 2 files changed, 32 insertions(+), 24 deletions(-) diff --git a/cmd/neofs-adm/internal/modules/morph/generate_test.go b/cmd/neofs-adm/internal/modules/morph/generate_test.go index 1e2e0c83..f3acae94 100644 --- a/cmd/neofs-adm/internal/modules/morph/generate_test.go +++ b/cmd/neofs-adm/internal/modules/morph/generate_test.go @@ -19,6 +19,8 @@ import ( "golang.org/x/term" ) +const testContractPassword = "grouppass" + func TestGenerateAlphabet(t *testing.T) { const size = 4 @@ -59,7 +61,15 @@ func TestGenerateAlphabet(t *testing.T) { require.Error(t, generateAlphabetCreds(cmd, nil)) }) - testGenerateAlphabet(t, buf, v, size, walletDir) + buf.Reset() + v.Set(alphabetWalletsFlag, walletDir) + require.NoError(t, generateAlphabetCmd.Flags().Set(alphabetSizeFlag, strconv.FormatUint(size, 10))) + for i := uint64(0); i < size; i++ { + buf.WriteString(strconv.FormatUint(i, 10) + "\r") + } + + buf.WriteString(testContractPassword + "\r") + require.NoError(t, generateAlphabetCreds(generateAlphabetCmd, nil)) for i := uint64(0); i < size; i++ { p := filepath.Join(walletDir, innerring.GlagoliticLetter(i).String()+".json") @@ -109,17 +119,3 @@ func newTempDir(t *testing.T) string { }) return dir } - -const testContractPassword = "grouppass" - -func testGenerateAlphabet(t *testing.T, buf *bytes.Buffer, v *viper.Viper, size uint64, walletDir string) { - buf.Reset() - v.Set(alphabetWalletsFlag, walletDir) - require.NoError(t, generateAlphabetCmd.Flags().Set(alphabetSizeFlag, strconv.FormatUint(size, 10))) - for i := uint64(0); i < size; i++ { - buf.WriteString(strconv.FormatUint(i, 10) + "\r") - } - - buf.WriteString(testContractPassword + "\r") - require.NoError(t, generateAlphabetCreds(generateAlphabetCmd, nil)) -} diff --git a/cmd/neofs-adm/internal/modules/morph/initialize_test.go b/cmd/neofs-adm/internal/modules/morph/initialize_test.go index 925a792d..3535b469 100644 --- a/cmd/neofs-adm/internal/modules/morph/initialize_test.go +++ b/cmd/neofs-adm/internal/modules/morph/initialize_test.go @@ -16,20 +16,36 @@ import ( "gopkg.in/yaml.v3" ) +const contractsPath = "../../../../../../neofs-contract/neofs-contract-v0.16.0.tar.gz" + func TestInitialize(t *testing.T) { // This test needs neofs-contract tarball, so it is skipped by default. // It is here for performing local testing after the changes. t.Skip() + t.Run("4 nodes", func(t *testing.T) { + testInitialize(t, 4) + }) + t.Run("7 nodes", func(t *testing.T) { + testInitialize(t, 7) + }) +} - const contractsPath = "../../../../../../neofs-contract/neofs-contract-v0.16.0.tar.gz" - const committeeSize = 7 - const validatorCount = committeeSize +func testInitialize(t *testing.T, committeeSize int) { + validatorCount := committeeSize walletDir := newTempDir(t) - buf := setupTestTerminal(t) v := viper.GetViper() - testGenerateAlphabet(t, buf, v, committeeSize, walletDir) + v.Set(alphabetWalletsFlag, walletDir) + + sizeStr := strconv.FormatUint(uint64(committeeSize), 10) + require.NoError(t, generateAlphabetCmd.Flags().Set(alphabetSizeFlag, sizeStr)) + + for i := 0; i < committeeSize; i++ { + v.Set("credentials."+innerring.GlagoliticLetter(i).String(), strconv.FormatUint(uint64(i), 10)) + } + v.Set("credentials.contract", testContractPassword) + require.NoError(t, generateAlphabetCreds(generateAlphabetCmd, nil)) var pubs []string for i := 0; i < committeeSize; i++ { @@ -61,10 +77,6 @@ func TestInitialize(t *testing.T) { v.Set(protoConfigPath, protoPath) // Set to the path or remove the next statement to download from the network. require.NoError(t, initCmd.Flags().Set(contractsInitFlag, contractsPath)) - for i := 0; i < committeeSize; i++ { - v.Set("credentials."+innerring.GlagoliticLetter(i).String(), strconv.FormatUint(uint64(i), 10)) - } - v.Set("credentials.contract", testContractPassword) v.Set(localDumpFlag, filepath.Join(walletDir, "out")) v.Set(alphabetWalletsFlag, walletDir) v.Set(epochDurationInitFlag, 1)