[Federation] Unit tests for dry run support in kubefed init

This commit is contained in:
Irfan Ur Rehman 2016-11-10 19:01:54 +05:30
parent 0462c656e8
commit 2309821c5c

View File

@ -79,6 +79,7 @@ func TestInitFederation(t *testing.T) {
etcdPVCapacity string
expectedErr string
dnsProvider string
dryRun string
}{
{
federation: "union",
@ -90,6 +91,7 @@ func TestInitFederation(t *testing.T) {
etcdPVCapacity: "5Gi",
expectedErr: "",
dnsProvider: "test-dns-provider",
dryRun: "",
},
{
federation: "union",
@ -101,9 +103,24 @@ func TestInitFederation(t *testing.T) {
etcdPVCapacity: "", //test for default value of pvc-size
expectedErr: "",
dnsProvider: "", //test for default value of dns provider
dryRun: "",
},
{
federation: "union",
kubeconfigGlobal: fakeKubeFiles[0],
kubeconfigExplicit: "",
dnsZoneName: "example.test.",
lbIP: "10.20.30.40",
image: "example.test/foo:bar",
etcdPVCapacity: "",
expectedErr: "",
dnsProvider: "test-dns-provider",
dryRun: "valid-run",
},
}
//TODO: implement a negative case for dry run
for i, tc := range testCases {
cmdErrMsg = ""
dnsProvider = ""
@ -136,13 +153,22 @@ func TestInitFederation(t *testing.T) {
if "" != tc.etcdPVCapacity {
cmd.Flags().Set("etcd-pv-capacity", tc.etcdPVCapacity)
}
if "valid-run" == tc.dryRun {
cmd.Flags().Set("dry-run", "true")
}
cmd.Run(cmd, []string{tc.federation})
if tc.expectedErr == "" {
// uses the name from the federation, not the response
// Actual data passed are tested in the fake secret and cluster
// REST clients.
want := fmt.Sprintf("Federation API server is running at: %s\n", tc.lbIP)
want := ""
if "" != tc.dryRun {
want = fmt.Sprintf("Federation control plane runs (dry run)\n")
} else {
want = fmt.Sprintf("Federation API server is running at: %s\n", tc.lbIP)
}
if got := buf.String(); got != want {
t.Errorf("[%d] unexpected output: got: %s, want: %s", i, got, want)
if cmdErrMsg != "" {