Merge pull request #6980 from sharifelgamal/cp-bc

add unit test of PrimaryControlPlane
pull/6986/head
Medya Ghazizadeh 2020-03-10 14:46:58 -07:00 committed by GitHub
commit 3780953132
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 69 additions and 11 deletions

View File

@ -34,7 +34,7 @@ func TestListProfiles(t *testing.T) {
vmDriver string vmDriver string
}{ }{
{0, "p1", "hyperkit"}, {0, "p1", "hyperkit"},
{1, "p2", "virtualbox"}, {1, "p2_newformat", "virtualbox"},
} }
// test cases for invalid profiles // test cases for invalid profiles
@ -109,7 +109,7 @@ func TestProfileExists(t *testing.T) {
expected bool expected bool
}{ }{
{"p1", true}, {"p1", true},
{"p2", true}, {"p2_newformat", true},
{"p3_empty", true}, {"p3_empty", true},
{"p4_invalid_file", true}, {"p4_invalid_file", true},
{"p5_partial_config", true}, {"p5_partial_config", true},
@ -218,3 +218,47 @@ func TestDeleteProfile(t *testing.T) {
} }
} }
func TestGetPrimaryControlPlane(t *testing.T) {
miniDir, err := filepath.Abs("./testdata/.minikube2")
if err != nil {
t.Errorf("error getting dir path for ./testdata/.minikube : %v", err)
}
var tests = []struct {
description string
profile string
expectedIP string
expectedPort int
expectedName string
}{
{"old style", "p1", "192.168.64.75", 8443, "minikube"},
{"new style", "p2_newformat", "192.168.99.136", 8443, "m01"},
}
for _, tc := range tests {
cc, err := DefaultLoader.LoadConfigFromFile(tc.profile, miniDir)
if err != nil {
t.Fatalf("Failed to load config for %s", tc.description)
}
n, err := PrimaryControlPlane(cc)
if err != nil {
t.Fatalf("Unexpexted error getting primary control plane: %v", err)
}
if n.Name != tc.expectedName {
t.Errorf("Unexpected name. expected: %s, got: %s", tc.expectedName, n.Name)
}
if n.IP != tc.expectedIP {
t.Errorf("Unexpected name. expected: %s, got: %s", tc.expectedIP, n.IP)
}
if n.Port != tc.expectedPort {
t.Errorf("Unexpected name. expected: %d, got: %d", tc.expectedPort, n.Port)
}
}
}

View File

@ -29,9 +29,6 @@
}, },
"KubernetesConfig": { "KubernetesConfig": {
"KubernetesVersion": "v1.15.0", "KubernetesVersion": "v1.15.0",
"NodeIP": "192.168.99.136",
"NodePort": 8443,
"NodeName": "minikube",
"APIServerName": "minikubeCA", "APIServerName": "minikubeCA",
"APIServerNames": null, "APIServerNames": null,
"APIServerIPs": null, "APIServerIPs": null,
@ -45,5 +42,15 @@
"ExtraOptions": null, "ExtraOptions": null,
"ShouldLoadCachedImages": true, "ShouldLoadCachedImages": true,
"EnableDefaultCNI": false "EnableDefaultCNI": false
} },
"Nodes": [
{
"Name": "m01",
"IP": "192.168.99.136",
"Port": 8443,
"KubernetesVersion": "v1.15.0",
"ControlPlane": true,
"Worker": true
}
]
} }

View File

@ -1,5 +1,5 @@
{ {
"Name": "p2", "Name": "p2_newformat",
"KeepContext": false, "KeepContext": false,
"MinikubeISO": "https://storage.googleapis.com/minikube/iso/minikube-v1.2.0.iso", "MinikubeISO": "https://storage.googleapis.com/minikube/iso/minikube-v1.2.0.iso",
"Memory": 2000, "Memory": 2000,
@ -28,9 +28,6 @@
"HostDNSResolver": true, "HostDNSResolver": true,
"KubernetesConfig": { "KubernetesConfig": {
"KubernetesVersion": "v1.15.0", "KubernetesVersion": "v1.15.0",
"NodeIP": "192.168.99.136",
"NodePort": 8443,
"NodeName": "minikube",
"APIServerName": "minikubeCA", "APIServerName": "minikubeCA",
"APIServerNames": null, "APIServerNames": null,
"APIServerIPs": null, "APIServerIPs": null,
@ -44,5 +41,15 @@
"ExtraOptions": null, "ExtraOptions": null,
"ShouldLoadCachedImages": true, "ShouldLoadCachedImages": true,
"EnableDefaultCNI": false "EnableDefaultCNI": false
} },
"Nodes": [
{
"Name": "m01",
"IP": "192.168.99.136",
"Port": 8443,
"KubernetesVersion": "v1.15.0",
"ControlPlane": true,
"Worker": true
}
]
} }