Skip to content

Commit c186de0

Browse files
committed
Fixing k8s.io/kubernetes/cmd/kubeadm/app/util/staticpod unit tests on Windows
Signed-off-by: Mark Rossetti <[email protected]>
1 parent 2ca9e2d commit c186de0

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

cmd/kubeadm/app/util/staticpod/utils_test.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"os"
2222
"path/filepath"
2323
"reflect"
24+
goruntime "runtime"
2425
"sort"
2526
"strconv"
2627
"strings"
@@ -695,6 +696,17 @@ func TestReadStaticPodFromDisk(t *testing.T) {
695696
}
696697
}
697698

699+
// getFileNotFoundForOS returns the expected error message for a file not found error on the current OS
700+
// - on Windows, the error message is "The system cannot find the file specified"
701+
// - on other, the error message is "no such file or directory"
702+
func getFileNotFoundForOS() string {
703+
if goruntime.GOOS == "windows" {
704+
return "The system cannot find the file specified"
705+
} else {
706+
return "no such file or directory"
707+
}
708+
}
709+
698710
func TestReadMultipleStaticPodsFromDisk(t *testing.T) {
699711
getTestPod := func(name string) *v1.Pod {
700712
return &v1.Pod{
@@ -738,9 +750,9 @@ func TestReadMultipleStaticPodsFromDisk(t *testing.T) {
738750
setup: func(dir string) {},
739751
components: kubeadmconstants.ControlPlaneComponents,
740752
expectedErrorContains: []string{
741-
"kube-apiserver.yaml: no such file or directory",
742-
"kube-controller-manager.yaml: no such file or directory",
743-
"kube-scheduler.yaml: no such file or directory",
753+
"kube-apiserver.yaml: " + getFileNotFoundForOS(),
754+
"kube-controller-manager.yaml: " + getFileNotFoundForOS(),
755+
"kube-scheduler.yaml: " + getFileNotFoundForOS(),
744756
},
745757
},
746758
}

0 commit comments

Comments
 (0)