storj/cmd/multinode/main_test.go
Clement Sam 60c8280565 cmd/multinode: add add command to multinode
This change adds an add command to the multinode CLI.

The add command takes a json <file> as argument.
If dash (-) is specified, it reads data from stdin.

The <file> specified can be json file containing array of
nodes data or a single node object.

Change-Id: I44d68486dc9aea0bd0311a40e84d3262a0303aef
2021-12-14 17:05:52 +00:00

68 lines
1.6 KiB
Go

// Copyright (C) 2021 Storj Labs, Inc.
// See LICENSE for copying information.
package main
import (
"testing"
"github.com/stretchr/testify/require"
"storj.io/common/storj"
)
func Test_unmarshalJSONNodes(t *testing.T) {
nodeID, err := storj.NodeIDFromString("1MJ7R1cqGrFnELPY3YKd62TBJ6vE8x9yPKPwUFHUx6G8oypezR")
require.NoError(t, err)
t.Run("valid json object", func(t *testing.T) {
nodesJSONData := `
{
"name": "Storagenode 1",
"id":"1MJ7R1cqGrFnELPY3YKd62TBJ6vE8x9yPKPwUFHUx6G8oypezR",
"publicAddress": "awn7k09ts6mxbgau.myfritz.net:13010",
"apiSecret": "b_yeI0OBKBusBVN4_dHxpxlwdTyoFPwtEuHv9ACl9jI="
}
`
expectedNodeInfo := []nodeInfo{
{
NodeID: nodeID,
PublicAddress: "awn7k09ts6mxbgau.myfritz.net:13010",
APISecret: "b_yeI0OBKBusBVN4_dHxpxlwdTyoFPwtEuHv9ACl9jI=",
Name: "Storagenode 1",
},
}
got, err := unmarshalJSONNodes([]byte(nodesJSONData))
require.NoError(t, err)
require.Equal(t, expectedNodeInfo, got)
})
t.Run("valid json array", func(t *testing.T) {
nodesJSONData := `
[
{
"name": "Storagenode 1",
"id":"1MJ7R1cqGrFnELPY3YKd62TBJ6vE8x9yPKPwUFHUx6G8oypezR",
"publicAddress": "awn7k09ts6mxbgau.myfritz.net:13010",
"apiSecret": "b_yeI0OBKBusBVN4_dHxpxlwdTyoFPwtEuHv9ACl9jI="
}
]
`
expectedNodeInfo := []nodeInfo{
{
NodeID: nodeID,
PublicAddress: "awn7k09ts6mxbgau.myfritz.net:13010",
APISecret: "b_yeI0OBKBusBVN4_dHxpxlwdTyoFPwtEuHv9ACl9jI=",
Name: "Storagenode 1",
},
}
got, err := unmarshalJSONNodes([]byte(nodesJSONData))
require.NoError(t, err)
require.Equal(t, expectedNodeInfo, got)
})
}