2022-03-22 11:03:15 -04:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"encoding/base64"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestGetGCPValidator(t *testing.T) {
|
|
|
|
testCases := map[string]struct {
|
2022-04-26 10:54:05 -04:00
|
|
|
ownerID string
|
|
|
|
clusterID string
|
|
|
|
wantErr bool
|
2022-03-22 11:03:15 -04:00
|
|
|
}{
|
|
|
|
"no input": {
|
2022-04-26 10:54:05 -04:00
|
|
|
ownerID: "",
|
|
|
|
clusterID: "",
|
|
|
|
wantErr: true,
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
|
|
|
"unencoded secret ID": {
|
2022-04-26 10:54:05 -04:00
|
|
|
ownerID: "owner-id",
|
|
|
|
clusterID: base64.StdEncoding.EncodeToString([]byte("unique-id")),
|
|
|
|
wantErr: true,
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
|
|
|
"unencoded cluster ID": {
|
2022-04-26 10:54:05 -04:00
|
|
|
ownerID: base64.StdEncoding.EncodeToString([]byte("owner-id")),
|
|
|
|
clusterID: "unique-id",
|
|
|
|
wantErr: true,
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
|
|
|
"correct input": {
|
2022-04-26 10:54:05 -04:00
|
|
|
ownerID: base64.StdEncoding.EncodeToString([]byte("owner-id")),
|
|
|
|
clusterID: base64.StdEncoding.EncodeToString([]byte("unique-id")),
|
|
|
|
wantErr: false,
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for name, tc := range testCases {
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
require := require.New(t)
|
|
|
|
|
|
|
|
cmd := newVerifyGCPCmd()
|
|
|
|
cmd.Flags().String("owner-id", "", "")
|
|
|
|
cmd.Flags().String("unique-id", "", "")
|
|
|
|
require.NoError(cmd.Flags().Set("owner-id", tc.ownerID))
|
|
|
|
require.NoError(cmd.Flags().Set("unique-id", tc.clusterID))
|
|
|
|
var out bytes.Buffer
|
|
|
|
cmd.SetOut(&out)
|
|
|
|
var errOut bytes.Buffer
|
|
|
|
cmd.SetErr(&errOut)
|
|
|
|
|
|
|
|
_, err := getGCPValidator(cmd, map[uint32][]byte{
|
|
|
|
0: []byte("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"),
|
|
|
|
1: []byte("BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"),
|
|
|
|
})
|
2022-04-26 10:54:05 -04:00
|
|
|
if tc.wantErr {
|
2022-03-22 11:03:15 -04:00
|
|
|
assert.Error(err)
|
|
|
|
} else {
|
|
|
|
assert.NoError(err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|