From 839bd03621bf83e1d794adf9b68d2dc2b05c52be Mon Sep 17 00:00:00 2001 From: Ilya Zuyev Date: Thu, 14 Jan 2021 12:28:10 -0800 Subject: [PATCH] Add unit test for archTag() --- pkg/minikube/bootstrapper/images/images.go | 5 +++- .../bootstrapper/images/images_test.go | 29 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/pkg/minikube/bootstrapper/images/images.go b/pkg/minikube/bootstrapper/images/images.go index de5292e627..b1acc13c93 100644 --- a/pkg/minikube/bootstrapper/images/images.go +++ b/pkg/minikube/bootstrapper/images/images.go @@ -122,7 +122,10 @@ func etcd(v semver.Version, mirror string) string { // archTag returns a CPU architecture suffix for images func archTag(needsArchSuffix bool) string { - if runtime.GOARCH == "amd64" || !needsArchSuffix { + return archTagInt(runtime.GOARCH, needsArchSuffix) +} +func archTagInt(arch string, needsArchSuffix bool) string { + if arch == "amd64" || !needsArchSuffix { return ":" } return "-" + runtime.GOARCH + ":" diff --git a/pkg/minikube/bootstrapper/images/images_test.go b/pkg/minikube/bootstrapper/images/images_test.go index 3d77360340..5390daf617 100644 --- a/pkg/minikube/bootstrapper/images/images_test.go +++ b/pkg/minikube/bootstrapper/images/images_test.go @@ -17,6 +17,8 @@ limitations under the License. package images import ( + "fmt" + "runtime" "testing" "github.com/google/go-cmp/cmp" @@ -45,3 +47,30 @@ func TestAuxiliaryMirror(t *testing.T) { t.Errorf("images mismatch (-want +got):\n%s", diff) } } + +func TestArchTag(t *testing.T) { + tests := []struct { + arch string + suffix bool + expected string + }{ + { + "amd64", true, ":", + }, + { + "amd64", false, ":", + }, + { + "arm64", false, ":", + }, + { + "arm64", true, fmt.Sprintf("-%s:", runtime.GOARCH), + }, + } + for _, test := range tests { + if tag := archTagInt(test.arch, test.suffix); tag != test.expected { + t.Errorf("For arch: %v and suffix flag: '%v' expected %v got %v", + test.arch, test.suffix, test.expected, tag) + } + } +}