mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 14:07:14 +00:00
Merge pull request #111534 from claudiubelu/unittests-7
unittests: Fixes unit tests for Windows
This commit is contained in:
commit
38c659eb9f
@ -22,6 +22,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
goruntime "runtime"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/lithammer/dedent"
|
"github.com/lithammer/dedent"
|
||||||
@ -241,20 +242,26 @@ func TestDownloadCerts(t *testing.T) {
|
|||||||
// Check that the written files are either certificates or keys, and that they have
|
// Check that the written files are either certificates or keys, and that they have
|
||||||
// the expected permissions
|
// the expected permissions
|
||||||
if _, err := keyutil.ParsePrivateKeyPEM(diskCertData); err == nil {
|
if _, err := keyutil.ParsePrivateKeyPEM(diskCertData); err == nil {
|
||||||
if stat, err := os.Stat(certPath); err == nil {
|
// File permissions are set differently on Windows, which does not match the expectation below.
|
||||||
if stat.Mode() != keyFileMode {
|
if goruntime.GOOS != "windows" {
|
||||||
t.Errorf("key %q should have mode %#o, has %#o", certName, keyFileMode, stat.Mode())
|
if stat, err := os.Stat(certPath); err == nil {
|
||||||
|
if stat.Mode() != keyFileMode {
|
||||||
|
t.Errorf("key %q should have mode %#o, has %#o", certName, keyFileMode, stat.Mode())
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
t.Errorf("could not stat key %q: %v", certName, err)
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
t.Errorf("could not stat key %q: %v", certName, err)
|
|
||||||
}
|
}
|
||||||
} else if _, err := keyutil.ParsePublicKeysPEM(diskCertData); err == nil {
|
} else if _, err := keyutil.ParsePublicKeysPEM(diskCertData); err == nil {
|
||||||
if stat, err := os.Stat(certPath); err == nil {
|
// File permissions are set differently on Windows, which does not match the expectation below.
|
||||||
if stat.Mode() != certFileMode {
|
if goruntime.GOOS != "windows" {
|
||||||
t.Errorf("cert %q should have mode %#o, has %#o", certName, certFileMode, stat.Mode())
|
if stat, err := os.Stat(certPath); err == nil {
|
||||||
|
if stat.Mode() != certFileMode {
|
||||||
|
t.Errorf("cert %q should have mode %#o, has %#o", certName, certFileMode, stat.Mode())
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
t.Errorf("could not stat cert %q: %v", certName, err)
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
t.Errorf("could not stat cert %q: %v", certName, err)
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
t.Errorf("secret %q was not identified as a cert or as a key", certName)
|
t.Errorf("secret %q was not identified as a cert or as a key", certName)
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
//go:build !windows
|
||||||
|
// +build !windows
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Copyright 2017 The Kubernetes Authors.
|
Copyright 2017 The Kubernetes Authors.
|
||||||
|
|
32
cmd/kubeadm/app/util/copy_windows.go
Normal file
32
cmd/kubeadm/app/util/copy_windows.go
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
//go:build windows
|
||||||
|
// +build windows
|
||||||
|
|
||||||
|
/*
|
||||||
|
Copyright 2022 The Kubernetes Authors.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package util
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os/exec"
|
||||||
|
)
|
||||||
|
|
||||||
|
// CopyDir copies the content of a folder
|
||||||
|
func CopyDir(src string, dst string) error {
|
||||||
|
// /E Copies directories and subdirectories, including empty ones.
|
||||||
|
// /H Copies hidden and system files also.
|
||||||
|
cmd := exec.Command("xcopy", "/E", "/H", src, dst)
|
||||||
|
return cmd.Run()
|
||||||
|
}
|
@ -114,7 +114,8 @@ func evalSymlink(path string) (string, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// This command will give the target path of a given symlink
|
// This command will give the target path of a given symlink
|
||||||
cmd := fmt.Sprintf("(Get-Item -LiteralPath %q).Target", upperpath)
|
// The -Force parameter will allow Get-Item to also evaluate hidden folders, like AppData.
|
||||||
|
cmd := fmt.Sprintf("(Get-Item -Force -LiteralPath %q).Target", upperpath)
|
||||||
output, err := exec.Command("powershell", "/c", cmd).CombinedOutput()
|
output, err := exec.Command("powershell", "/c", cmd).CombinedOutput()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
Loading…
Reference in New Issue
Block a user