Merge pull request #6980 from sharifelgamal/cp-bc
add unit test of PrimaryControlPlanepull/6986/head
commit
3780953132
|
@ -34,7 +34,7 @@ func TestListProfiles(t *testing.T) {
|
|||
vmDriver string
|
||||
}{
|
||||
{0, "p1", "hyperkit"},
|
||||
{1, "p2", "virtualbox"},
|
||||
{1, "p2_newformat", "virtualbox"},
|
||||
}
|
||||
|
||||
// test cases for invalid profiles
|
||||
|
@ -109,7 +109,7 @@ func TestProfileExists(t *testing.T) {
|
|||
expected bool
|
||||
}{
|
||||
{"p1", true},
|
||||
{"p2", true},
|
||||
{"p2_newformat", true},
|
||||
{"p3_empty", true},
|
||||
{"p4_invalid_file", 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)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -29,9 +29,6 @@
|
|||
},
|
||||
"KubernetesConfig": {
|
||||
"KubernetesVersion": "v1.15.0",
|
||||
"NodeIP": "192.168.99.136",
|
||||
"NodePort": 8443,
|
||||
"NodeName": "minikube",
|
||||
"APIServerName": "minikubeCA",
|
||||
"APIServerNames": null,
|
||||
"APIServerIPs": null,
|
||||
|
@ -45,5 +42,15 @@
|
|||
"ExtraOptions": null,
|
||||
"ShouldLoadCachedImages": true,
|
||||
"EnableDefaultCNI": false
|
||||
}
|
||||
},
|
||||
"Nodes": [
|
||||
{
|
||||
"Name": "m01",
|
||||
"IP": "192.168.99.136",
|
||||
"Port": 8443,
|
||||
"KubernetesVersion": "v1.15.0",
|
||||
"ControlPlane": true,
|
||||
"Worker": true
|
||||
}
|
||||
]
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"Name": "p2",
|
||||
"Name": "p2_newformat",
|
||||
"KeepContext": false,
|
||||
"MinikubeISO": "https://storage.googleapis.com/minikube/iso/minikube-v1.2.0.iso",
|
||||
"Memory": 2000,
|
||||
|
@ -28,9 +28,6 @@
|
|||
"HostDNSResolver": true,
|
||||
"KubernetesConfig": {
|
||||
"KubernetesVersion": "v1.15.0",
|
||||
"NodeIP": "192.168.99.136",
|
||||
"NodePort": 8443,
|
||||
"NodeName": "minikube",
|
||||
"APIServerName": "minikubeCA",
|
||||
"APIServerNames": null,
|
||||
"APIServerIPs": null,
|
||||
|
@ -44,5 +41,15 @@
|
|||
"ExtraOptions": null,
|
||||
"ShouldLoadCachedImages": true,
|
||||
"EnableDefaultCNI": false
|
||||
}
|
||||
},
|
||||
"Nodes": [
|
||||
{
|
||||
"Name": "m01",
|
||||
"IP": "192.168.99.136",
|
||||
"Port": 8443,
|
||||
"KubernetesVersion": "v1.15.0",
|
||||
"ControlPlane": true,
|
||||
"Worker": true
|
||||
}
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue