Add and refactor cluster cmd unit tests

This patch adds some missing cmd unit tests for cluster module
and refactors current ones as well, slightly improving test coverage.

Change-Id: I80c449e213d9aed9abd11fe794afac07ca16bdc6
Signed-off-by: Ruslan Aliev <raliev@mirantis.com>
This commit is contained in:
Ruslan Aliev 2020-07-30 16:00:51 -05:00
parent 7964f0cd77
commit 53e4f7ffc6
9 changed files with 114 additions and 6 deletions

View File

@ -35,11 +35,6 @@ func TestNewClusterCommand(t *testing.T) {
CmdLine: "--help",
Cmd: cluster.NewClusterCommand(fakeRootSettings),
},
{
Name: "cluster-init-cmd-with-help",
CmdLine: "--help",
Cmd: cluster.NewInitCommand(fakeRootSettings),
},
}
for _, testcase := range tests {
testutil.RunTest(t, testcase)

42
cmd/cluster/init_test.go Executable file
View File

@ -0,0 +1,42 @@
/*
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"
"opendev.org/airship/airshipctl/cmd/cluster"
"opendev.org/airship/airshipctl/pkg/environment"
"opendev.org/airship/airshipctl/testutil"
)
func TestNewClusterInitCmd(t *testing.T) {
fakeRootSettings := &environment.AirshipCTLSettings{
AirshipConfigPath: "../../testdata/k8s/config.yaml",
KubeConfigPath: "../../testdata/k8s/kubeconfig.yaml",
}
fakeRootSettings.InitConfig()
tests := []*testutil.CmdTest{
{
Name: "cluster-init-cmd-with-help",
CmdLine: "--help",
Cmd: cluster.NewInitCommand(fakeRootSettings),
},
}
for _, testcase := range tests {
testutil.RunTest(t, testcase)
}
}

41
cmd/cluster/move_test.go Executable file
View File

@ -0,0 +1,41 @@
/*
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"
"opendev.org/airship/airshipctl/cmd/cluster"
"opendev.org/airship/airshipctl/pkg/environment"
"opendev.org/airship/airshipctl/testutil"
)
func TestNewClusterMoveCmd(t *testing.T) {
fakeRootSettings := &environment.AirshipCTLSettings{
AirshipConfigPath: "../../testdata/k8s/config.yaml",
KubeConfigPath: "../../testdata/k8s/kubeconfig.yaml",
}
tests := []*testutil.CmdTest{
{
Name: "cluster-move-cmd-with-help",
CmdLine: "--help",
Cmd: cluster.NewMoveCommand(fakeRootSettings),
},
}
for _, testcase := range tests {
testutil.RunTest(t, testcase)
}
}

View File

@ -34,7 +34,7 @@ const (
fixturesPath = "testdata/statusmap"
)
func TestStatusCmd(t *testing.T) {
func TestNewClusterStatusCmd(t *testing.T) {
tests := []struct {
cmdTest *testutil.CmdTest
resources []runtime.Object
@ -46,6 +46,12 @@ func TestStatusCmd(t *testing.T) {
CmdLine: "",
},
},
{
cmdTest: &testutil.CmdTest{
Name: "cluster-status-cmd-with-help",
CmdLine: "--help",
},
},
{
cmdTest: &testutil.CmdTest{
Name: "check-status-with-resources",

View File

@ -0,0 +1,17 @@
Move Cluster API objects, provider specific objects and all dependencies to the target cluster.
Note: The destination cluster MUST have the required provider components installed.
Usage:
move [flags]
Examples:
Move Cluster API objects, provider specific objects and all dependencies to the target cluster.
airshipctl cluster move --target-context <context name>
Flags:
-h, --help help for move
--target-context string Context to be used within the kubeconfig file for the target cluster. If empty, current context will be used.

View File

@ -0,0 +1,7 @@
Retrieve statuses of deployed cluster components
Usage:
status [flags]
Flags:
-h, --help help for status