Fixing k8s.io/kubernetes/cmd/kubeadm/app/util/staticpod unit tests on Windows

Signed-off-by: Mark Rossetti <marosset@microsoft.com>
This commit is contained in:
Mark Rossetti 2025-02-19 12:51:19 -08:00
parent 2ca9e2d28f
commit c186de0080
No known key found for this signature in database
GPG Key ID: 33F9E7BD7AA6C1B0

View File

@ -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(),
},
},
}