Merge pull request #130289 from marosset/windows-unit-tests-cmd-kubeadm-app-util-static-pod-fixes

Fixing k8s.io/kubernetes/cmd/kubeadm/app/util/staticpod unit tests on Windows
This commit is contained in:
Kubernetes Prow Robot 2025-02-20 15:00:26 -08:00 committed by GitHub
commit 19feb379b3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

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