From c186de0080966ed7e9f7f7609263007e61d969f8 Mon Sep 17 00:00:00 2001 From: Mark Rossetti Date: Wed, 19 Feb 2025 12:51:19 -0800 Subject: [PATCH] Fixing k8s.io/kubernetes/cmd/kubeadm/app/util/staticpod unit tests on Windows Signed-off-by: Mark Rossetti --- cmd/kubeadm/app/util/staticpod/utils_test.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/cmd/kubeadm/app/util/staticpod/utils_test.go b/cmd/kubeadm/app/util/staticpod/utils_test.go index f9c71670213..85ecccfc277 100644 --- a/cmd/kubeadm/app/util/staticpod/utils_test.go +++ b/cmd/kubeadm/app/util/staticpod/utils_test.go @@ -21,6 +21,7 @@ import ( "os" "path/filepath" "reflect" + goruntime "runtime" "sort" "strconv" "strings" @@ -695,6 +696,17 @@ func TestReadStaticPodFromDisk(t *testing.T) { } } +// getFileNotFoundForOS returns the expected error message for a file not found error on the current OS +// - on Windows, the error message is "The system cannot find the file specified" +// - on other, the error message is "no such file or directory" +func getFileNotFoundForOS() string { + if goruntime.GOOS == "windows" { + return "The system cannot find the file specified" + } else { + return "no such file or directory" + } +} + func TestReadMultipleStaticPodsFromDisk(t *testing.T) { getTestPod := func(name string) *v1.Pod { return &v1.Pod{ @@ -738,9 +750,9 @@ func TestReadMultipleStaticPodsFromDisk(t *testing.T) { setup: func(dir string) {}, components: kubeadmconstants.ControlPlaneComponents, expectedErrorContains: []string{ - "kube-apiserver.yaml: no such file or directory", - "kube-controller-manager.yaml: no such file or directory", - "kube-scheduler.yaml: no such file or directory", + "kube-apiserver.yaml: " + getFileNotFoundForOS(), + "kube-controller-manager.yaml: " + getFileNotFoundForOS(), + "kube-scheduler.yaml: " + getFileNotFoundForOS(), }, }, }