-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathzwalletcli_get_id_test.go
69 lines (55 loc) · 2.53 KB
/
zwalletcli_get_id_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package cli_tests
import (
"fmt"
"reflect"
"strings"
"testing"
"time"
"github.com/0chain/system_test/internal/api/util/test"
cliutils "github.com/0chain/system_test/internal/cli/util"
"github.com/stretchr/testify/require"
)
func TestGetId(testSetup *testing.T) {
t := test.NewSystemTest(testSetup)
t.SetSmokeTests("get miner id should work")
t.Parallel()
t.Run("get miner id should work", func(t *test.SystemTest) {
miners := getMinersList(t)
minerUrl := fmt.Sprint("http://", miners.Nodes[0].Host, ":", miners.Nodes[0].Port)
output, err := getId(t, configPath, minerUrl, true)
require.Nil(t, err, "get id failed", strings.Join(output, "\n"))
require.Greater(t, len(output), 1, "Expected output length to be at least 2", strings.Join(output, "\n"))
require.Equal(t, "URL: "+minerUrl, output[len(output)-2], strings.Join(output, "\n"))
require.Equal(t, "ID: "+miners.Nodes[0].ID, output[len(output)-1], strings.Join(output, "\n"))
})
t.Run("get sharder id should work", func(t *test.SystemTest) {
createWallet(t)
sharders := getShardersList(t)
sharderKey := reflect.ValueOf(sharders).MapKeys()[0].String()
sharder := sharders[sharderKey]
sharderUrl := fmt.Sprint("http://", sharder.Host, ":", sharder.Port)
require.NotNil(t, sharder)
output, err := getId(t, configPath, sharderUrl, true)
require.Nil(t, err, "get is failed", strings.Join(output, "\n"))
require.Greater(t, len(output), 1, "Expected output length to be at least 2", strings.Join(output, "\n"))
require.Equal(t, "URL: "+sharderUrl, output[len(output)-2], strings.Join(output, "\n"))
require.Equal(t, "ID: "+sharder.ID, output[len(output)-1], strings.Join(output, "\n"))
})
t.Run("get blobber id should not work", func(t *test.SystemTest) {
createWallet(t)
blobbers := getBlobbersList(t)
blobberUrl := blobbers[0].Url
output, err := getId(t, configPath, blobberUrl, false)
require.NotNil(t, err, "expected get id to fail", strings.Join(output, "\n"))
require.Len(t, output, 1, strings.Join(output, "\n"))
require.Equal(t, "Error: ID not found", output[0], strings.Join(output, "\n"))
})
}
func getId(t *test.SystemTest, cliConfigFilename, url string, retry bool) ([]string, error) {
t.Logf("getting id for [%s]...", url)
if retry {
return cliutils.RunCommand(t, fmt.Sprintf("./zwallet getid --silent --configDir ./config --url %s --config %s", url, cliConfigFilename), 3, time.Second)
} else {
return cliutils.RunCommandWithoutRetry(fmt.Sprintf("./zwallet getid --silent --configDir ./config --url %s --config %s", url, cliConfigFilename))
}
}