mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-14 06:15:45 +00:00
[Federation] Unit tests for dry run support in kubefed init
This commit is contained in:
parent
0462c656e8
commit
2309821c5c
@ -79,6 +79,7 @@ func TestInitFederation(t *testing.T) {
|
|||||||
etcdPVCapacity string
|
etcdPVCapacity string
|
||||||
expectedErr string
|
expectedErr string
|
||||||
dnsProvider string
|
dnsProvider string
|
||||||
|
dryRun string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
federation: "union",
|
federation: "union",
|
||||||
@ -90,6 +91,7 @@ func TestInitFederation(t *testing.T) {
|
|||||||
etcdPVCapacity: "5Gi",
|
etcdPVCapacity: "5Gi",
|
||||||
expectedErr: "",
|
expectedErr: "",
|
||||||
dnsProvider: "test-dns-provider",
|
dnsProvider: "test-dns-provider",
|
||||||
|
dryRun: "",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
federation: "union",
|
federation: "union",
|
||||||
@ -101,9 +103,24 @@ func TestInitFederation(t *testing.T) {
|
|||||||
etcdPVCapacity: "", //test for default value of pvc-size
|
etcdPVCapacity: "", //test for default value of pvc-size
|
||||||
expectedErr: "",
|
expectedErr: "",
|
||||||
dnsProvider: "", //test for default value of dns provider
|
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 {
|
for i, tc := range testCases {
|
||||||
cmdErrMsg = ""
|
cmdErrMsg = ""
|
||||||
dnsProvider = ""
|
dnsProvider = ""
|
||||||
@ -136,13 +153,22 @@ func TestInitFederation(t *testing.T) {
|
|||||||
if "" != tc.etcdPVCapacity {
|
if "" != tc.etcdPVCapacity {
|
||||||
cmd.Flags().Set("etcd-pv-capacity", 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})
|
cmd.Run(cmd, []string{tc.federation})
|
||||||
|
|
||||||
if tc.expectedErr == "" {
|
if tc.expectedErr == "" {
|
||||||
// uses the name from the federation, not the response
|
// uses the name from the federation, not the response
|
||||||
// Actual data passed are tested in the fake secret and cluster
|
// Actual data passed are tested in the fake secret and cluster
|
||||||
// REST clients.
|
// 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 {
|
if got := buf.String(); got != want {
|
||||||
t.Errorf("[%d] unexpected output: got: %s, want: %s", i, got, want)
|
t.Errorf("[%d] unexpected output: got: %s, want: %s", i, got, want)
|
||||||
if cmdErrMsg != "" {
|
if cmdErrMsg != "" {
|
||||||
|
Loading…
Reference in New Issue
Block a user