86 lines
1.5 KiB
Go
86 lines
1.5 KiB
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"isle/daemon/daecommon"
|
||
|
"isle/toolkit"
|
||
|
"testing"
|
||
|
)
|
||
|
|
||
|
func TestStorageAllocationList(t *testing.T) {
|
||
|
t.Parallel()
|
||
|
|
||
|
tests := []struct {
|
||
|
name string
|
||
|
allocs []daecommon.ConfigStorageAllocation
|
||
|
want any
|
||
|
}{
|
||
|
{
|
||
|
name: "empty",
|
||
|
allocs: nil,
|
||
|
want: []any{},
|
||
|
},
|
||
|
{
|
||
|
// results should get sorted according to RPCPort, with index
|
||
|
// reflecting that order.
|
||
|
name: "success",
|
||
|
allocs: []daecommon.ConfigStorageAllocation{
|
||
|
{
|
||
|
DataPath: "b",
|
||
|
MetaPath: "B",
|
||
|
Capacity: 2,
|
||
|
S3APIPort: 2000,
|
||
|
RPCPort: 2001,
|
||
|
AdminPort: 2002,
|
||
|
},
|
||
|
{
|
||
|
DataPath: "a",
|
||
|
MetaPath: "A",
|
||
|
Capacity: 1,
|
||
|
S3APIPort: 1000,
|
||
|
RPCPort: 1001,
|
||
|
AdminPort: 1002,
|
||
|
},
|
||
|
},
|
||
|
want: []map[string]any{
|
||
|
{
|
||
|
"index": 0,
|
||
|
"data_path": "a",
|
||
|
"meta_path": "A",
|
||
|
"capacity": 1,
|
||
|
"s3_api_port": 1000,
|
||
|
"rpc_port": 1001,
|
||
|
"admin_port": 1002,
|
||
|
},
|
||
|
{
|
||
|
"index": 1,
|
||
|
"data_path": "b",
|
||
|
"meta_path": "B",
|
||
|
"capacity": 2,
|
||
|
"s3_api_port": 2000,
|
||
|
"rpc_port": 2001,
|
||
|
"admin_port": 2002,
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
}
|
||
|
|
||
|
for _, test := range tests {
|
||
|
t.Run(test.name, func(t *testing.T) {
|
||
|
var (
|
||
|
h = newRunHarness(t)
|
||
|
config daecommon.NetworkConfig
|
||
|
)
|
||
|
|
||
|
config.Storage.Allocations = test.allocs
|
||
|
|
||
|
h.daemonRPC.
|
||
|
On("GetConfig", toolkit.MockArg[context.Context]()).
|
||
|
Return(config, nil).
|
||
|
Once()
|
||
|
|
||
|
h.runAssertStdout(t, test.want, "storage", "list-allocations")
|
||
|
})
|
||
|
}
|
||
|
}
|