Increase test coverage
* Few more minor changes to increase test coverage Change-Id: Id34a33732d3201637027cb3eb512a245acbd77b5
This commit is contained in:
parent
a37a8800cc
commit
d630b55235
@ -46,6 +46,32 @@ const (
|
||||
testCluster = "my_new-cluster"
|
||||
)
|
||||
|
||||
func TestConfigSetCluster(t *testing.T) {
|
||||
cmdTests := []*testutil.CmdTest{
|
||||
{
|
||||
Name: "config-cmd-set-cluster-with-help",
|
||||
CmdLine: "--help",
|
||||
Cmd: cmd.NewSetClusterCommand(nil),
|
||||
},
|
||||
{
|
||||
Name: "config-cmd-set-cluster-with-no-flags",
|
||||
CmdLine: "",
|
||||
Cmd: cmd.NewSetClusterCommand(nil),
|
||||
Error: fmt.Errorf("accepts %d arg(s), received %d", 1, 0),
|
||||
},
|
||||
{
|
||||
Name: "config-cmd-set-cluster-too-many-args",
|
||||
CmdLine: "arg1 arg2",
|
||||
Cmd: cmd.NewSetClusterCommand(nil),
|
||||
Error: fmt.Errorf("accepts at most %d arg(s), received %d", 1, 2),
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range cmdTests {
|
||||
testutil.RunTest(t, tt)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetClusterWithCAFile(t *testing.T) {
|
||||
given, cleanupGiven := testutil.InitConfig(t)
|
||||
defer cleanupGiven(t)
|
||||
|
37
cmd/config/testdata/TestConfigSetClusterGoldenOutput/config-cmd-set-cluster-too-many-args.golden
vendored
Normal file
37
cmd/config/testdata/TestConfigSetClusterGoldenOutput/config-cmd-set-cluster-too-many-args.golden
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
Error: accepts 1 arg(s), received 2
|
||||
Usage:
|
||||
set-cluster NAME [flags]
|
||||
|
||||
Examples:
|
||||
|
||||
# Set the server field on the ephemeral exampleCluster
|
||||
airshipctl config set-cluster exampleCluster \
|
||||
--cluster-type=ephemeral \
|
||||
--server=https://1.2.3.4
|
||||
|
||||
# Embed certificate authority data for the target exampleCluster
|
||||
airshipctl config set-cluster exampleCluster \
|
||||
--cluster-type=target \
|
||||
--client-certificate-authority=$HOME/.airship/ca/kubernetes.ca.crt \
|
||||
--embed-certs
|
||||
|
||||
# Disable certificate checking for the target exampleCluster
|
||||
airshipctl config set-cluster exampleCluster
|
||||
--cluster-type=target \
|
||||
--insecure-skip-tls-verify
|
||||
|
||||
# Configure client certificate for the target exampleCluster
|
||||
airshipctl config set-cluster exampleCluster \
|
||||
--cluster-type=target \
|
||||
--embed-certs \
|
||||
--client-certificate=$HOME/.airship/cert_file
|
||||
|
||||
|
||||
Flags:
|
||||
--certificate-authority string path to a certificate authority
|
||||
--cluster-type string the type of the cluster to add or modify
|
||||
--embed-certs if set, embed the client certificate/key into the cluster
|
||||
-h, --help help for set-cluster
|
||||
--insecure-skip-tls-verify if set, disable certificate checking (default true)
|
||||
--server string server to use for the cluster
|
||||
|
40
cmd/config/testdata/TestConfigSetClusterGoldenOutput/config-cmd-set-cluster-with-help.golden
vendored
Normal file
40
cmd/config/testdata/TestConfigSetClusterGoldenOutput/config-cmd-set-cluster-with-help.golden
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
Create or modify a cluster in the airshipctl config files.
|
||||
|
||||
Since a cluster can be either "ephemeral" or "target", you must specify
|
||||
cluster-type when managing clusters.
|
||||
|
||||
Usage:
|
||||
set-cluster NAME [flags]
|
||||
|
||||
Examples:
|
||||
|
||||
# Set the server field on the ephemeral exampleCluster
|
||||
airshipctl config set-cluster exampleCluster \
|
||||
--cluster-type=ephemeral \
|
||||
--server=https://1.2.3.4
|
||||
|
||||
# Embed certificate authority data for the target exampleCluster
|
||||
airshipctl config set-cluster exampleCluster \
|
||||
--cluster-type=target \
|
||||
--client-certificate-authority=$HOME/.airship/ca/kubernetes.ca.crt \
|
||||
--embed-certs
|
||||
|
||||
# Disable certificate checking for the target exampleCluster
|
||||
airshipctl config set-cluster exampleCluster
|
||||
--cluster-type=target \
|
||||
--insecure-skip-tls-verify
|
||||
|
||||
# Configure client certificate for the target exampleCluster
|
||||
airshipctl config set-cluster exampleCluster \
|
||||
--cluster-type=target \
|
||||
--embed-certs \
|
||||
--client-certificate=$HOME/.airship/cert_file
|
||||
|
||||
|
||||
Flags:
|
||||
--certificate-authority string path to a certificate authority
|
||||
--cluster-type string the type of the cluster to add or modify
|
||||
--embed-certs if set, embed the client certificate/key into the cluster
|
||||
-h, --help help for set-cluster
|
||||
--insecure-skip-tls-verify if set, disable certificate checking (default true)
|
||||
--server string server to use for the cluster
|
37
cmd/config/testdata/TestConfigSetClusterGoldenOutput/config-cmd-set-cluster-with-no-flags.golden
vendored
Normal file
37
cmd/config/testdata/TestConfigSetClusterGoldenOutput/config-cmd-set-cluster-with-no-flags.golden
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
Error: accepts 1 arg(s), received 0
|
||||
Usage:
|
||||
set-cluster NAME [flags]
|
||||
|
||||
Examples:
|
||||
|
||||
# Set the server field on the ephemeral exampleCluster
|
||||
airshipctl config set-cluster exampleCluster \
|
||||
--cluster-type=ephemeral \
|
||||
--server=https://1.2.3.4
|
||||
|
||||
# Embed certificate authority data for the target exampleCluster
|
||||
airshipctl config set-cluster exampleCluster \
|
||||
--cluster-type=target \
|
||||
--client-certificate-authority=$HOME/.airship/ca/kubernetes.ca.crt \
|
||||
--embed-certs
|
||||
|
||||
# Disable certificate checking for the target exampleCluster
|
||||
airshipctl config set-cluster exampleCluster
|
||||
--cluster-type=target \
|
||||
--insecure-skip-tls-verify
|
||||
|
||||
# Configure client certificate for the target exampleCluster
|
||||
airshipctl config set-cluster exampleCluster \
|
||||
--cluster-type=target \
|
||||
--embed-certs \
|
||||
--client-certificate=$HOME/.airship/cert_file
|
||||
|
||||
|
||||
Flags:
|
||||
--certificate-authority string path to a certificate authority
|
||||
--cluster-type string the type of the cluster to add or modify
|
||||
--embed-certs if set, embed the client certificate/key into the cluster
|
||||
-h, --help help for set-cluster
|
||||
--insecure-skip-tls-verify if set, disable certificate checking (default true)
|
||||
--server string server to use for the cluster
|
||||
|
@ -18,25 +18,30 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"opendev.org/airship/airshipctl/pkg/util"
|
||||
)
|
||||
|
||||
func TestReadYAMLFile(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
require := require.New(t)
|
||||
|
||||
var actual map[string]interface{}
|
||||
err := util.ReadYAMLFile("testdata/test.yaml", &actual)
|
||||
require.NoError(err, "Error while reading YAML")
|
||||
|
||||
actualString := actual["testString"]
|
||||
expectedString := "test"
|
||||
assert.Equal(expectedString, actualString)
|
||||
tests := []struct {
|
||||
testFile string
|
||||
isError bool
|
||||
}{
|
||||
{"testdata/test.yaml", false},
|
||||
{"testdata/incorrect.yaml", true},
|
||||
{"testdata/notfound.yaml", true},
|
||||
}
|
||||
|
||||
// test using an incorrect yaml
|
||||
err = util.ReadYAMLFile("testdata/incorrect.yaml", &actual)
|
||||
expectedString = "error converting YAML to JSON"
|
||||
require.Contains(err.Error(), expectedString)
|
||||
for _, test := range tests {
|
||||
err := util.ReadYAMLFile(test.testFile, &actual)
|
||||
if test.isError {
|
||||
assert.Error(err)
|
||||
} else {
|
||||
assert.NoError(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -46,4 +46,10 @@ func TestWriteFiles(t *testing.T) {
|
||||
// check if files are readable
|
||||
_, err = ioutil.ReadFile(testFile1)
|
||||
assert.NoError(t, err)
|
||||
|
||||
// test to fail WriteFiles with NonExistent Dir Path
|
||||
testFile3 := filepath.Join("NonExistentDir", "testFile3")
|
||||
fls[testFile3] = dummyData
|
||||
err = util.WriteFiles(fls, 0600)
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user