airshipctl/cmd/cluster/get_kubeconfig_test.go
Kostiantyn Kalynovskyi f24bf00d17 Get-kubeconfig return all cluster contexts
Now if we run `airshipctl cluster get-kubeconfig` without args
it will return kubeconfig for the entire site, which will have
contexts for every cluster defined in cluster map.

Relates-To: #460
Closes: #460

Change-Id: Icf1f09724a5c60ac520b1dbcbda69c3280ac4c7e
2021-03-17 19:27:14 +00:00

78 lines
2.0 KiB
Go

/*
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cluster_test
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"opendev.org/airship/airshipctl/cmd/cluster"
pkgcluster "opendev.org/airship/airshipctl/pkg/cluster"
"opendev.org/airship/airshipctl/testutil"
)
func TestNewKubeConfigCommandCmd(t *testing.T) {
tests := []*testutil.CmdTest{
{
Name: "cluster-get-kubeconfig-cmd-with-help",
CmdLine: "--help",
Cmd: cluster.NewGetKubeconfigCommand(nil),
},
}
for _, testcase := range tests {
testutil.RunTest(t, testcase)
}
}
func TestGetKubeconfArgs(t *testing.T) {
tests := []struct {
name string
args []string
expectedErrStr string
expectedClusterName string
}{
{
name: "success one cluster specified",
args: []string{"cluster01"},
expectedClusterName: "cluster01",
},
{
name: "success no cluster specified",
},
{
name: "error two cluster specified",
expectedErrStr: "accepts at most 1 arg(s)",
args: []string{"cluster01", "cluster02"},
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
cmd := &pkgcluster.GetKubeconfigCommand{}
args := cluster.GetKubeconfArgs(cmd)
err := args(cluster.NewGetKubeconfigCommand(nil), tt.args)
if tt.expectedErrStr != "" {
require.Error(t, err)
assert.Contains(t, err.Error(), tt.expectedErrStr)
} else {
assert.NoError(t, err)
assert.Equal(t, tt.expectedClusterName, cmd.ClusterName)
}
})
}
}