From 2a78178113e62fa27674542b16ec0b47db921ed1 Mon Sep 17 00:00:00 2001 From: Sharif Elgamal Date: Tue, 10 Mar 2020 10:30:58 -0700 Subject: [PATCH 1/2] add unit test of PrimaryControlPlane to avoid regressions related to config changes --- pkg/minikube/config/profile_test.go | 44 +++++++++++++++++++ .../.minikube2/profiles/p2/config.json | 15 +++++-- 2 files changed, 55 insertions(+), 4 deletions(-) diff --git a/pkg/minikube/config/profile_test.go b/pkg/minikube/config/profile_test.go index 06903d1808..3655be92a5 100644 --- a/pkg/minikube/config/profile_test.go +++ b/pkg/minikube/config/profile_test.go @@ -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", "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) + } + + } + +} diff --git a/pkg/minikube/config/testdata/.minikube2/profiles/p2/config.json b/pkg/minikube/config/testdata/.minikube2/profiles/p2/config.json index ab35410474..2c0e986c36 100644 --- a/pkg/minikube/config/testdata/.minikube2/profiles/p2/config.json +++ b/pkg/minikube/config/testdata/.minikube2/profiles/p2/config.json @@ -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 + } + ] } \ No newline at end of file From 46279786604c55eb21bf4b6fb87f1f74321e002d Mon Sep 17 00:00:00 2001 From: Sharif Elgamal Date: Tue, 10 Mar 2020 12:06:15 -0700 Subject: [PATCH 2/2] change profile name to be more explicit --- pkg/minikube/config/profile_test.go | 6 +++--- .../profiles/{p2 => p2_newformat}/config.json | 0 .../profiles/{p2 => p2_newformat}/config.json | 17 ++++++++++++----- 3 files changed, 15 insertions(+), 8 deletions(-) rename pkg/minikube/config/testdata/.minikube2/profiles/{p2 => p2_newformat}/config.json (100%) rename pkg/minikube/config/testdata/profile/.minikube/profiles/{p2 => p2_newformat}/config.json (82%) diff --git a/pkg/minikube/config/profile_test.go b/pkg/minikube/config/profile_test.go index 3655be92a5..805123ed19 100644 --- a/pkg/minikube/config/profile_test.go +++ b/pkg/minikube/config/profile_test.go @@ -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}, @@ -233,7 +233,7 @@ func TestGetPrimaryControlPlane(t *testing.T) { expectedName string }{ {"old style", "p1", "192.168.64.75", 8443, "minikube"}, - {"new style", "p2", "192.168.99.136", 8443, "m01"}, + {"new style", "p2_newformat", "192.168.99.136", 8443, "m01"}, } for _, tc := range tests { diff --git a/pkg/minikube/config/testdata/.minikube2/profiles/p2/config.json b/pkg/minikube/config/testdata/.minikube2/profiles/p2_newformat/config.json similarity index 100% rename from pkg/minikube/config/testdata/.minikube2/profiles/p2/config.json rename to pkg/minikube/config/testdata/.minikube2/profiles/p2_newformat/config.json diff --git a/pkg/minikube/config/testdata/profile/.minikube/profiles/p2/config.json b/pkg/minikube/config/testdata/profile/.minikube/profiles/p2_newformat/config.json similarity index 82% rename from pkg/minikube/config/testdata/profile/.minikube/profiles/p2/config.json rename to pkg/minikube/config/testdata/profile/.minikube/profiles/p2_newformat/config.json index a7bbd19b3f..b29f9295d7 100644 --- a/pkg/minikube/config/testdata/profile/.minikube/profiles/p2/config.json +++ b/pkg/minikube/config/testdata/profile/.minikube/profiles/p2_newformat/config.json @@ -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 + } + ] } \ No newline at end of file