mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Merge pull request #101217 from xuhdev/dir-test
TestGetPatchSetsForPathMustBeDirectory: Ensure the error type is os.PathError
This commit is contained in:
commit
f948c75ef2
@ -283,7 +283,11 @@ func getPatchSetsFromPath(targetPath string, knownTargets []string, output io.Wr
|
||||
goto return_path_error
|
||||
}
|
||||
if !info.IsDir() {
|
||||
err = errors.New("not a directory")
|
||||
err = &os.PathError{
|
||||
Op: "getPatchSetsFromPath",
|
||||
Path: info.Name(),
|
||||
Err: errors.New("not a directory"),
|
||||
}
|
||||
goto return_path_error
|
||||
}
|
||||
|
||||
|
@ -24,6 +24,7 @@ import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
)
|
||||
@ -165,15 +166,16 @@ func TestCreatePatchSet(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetPatchSetsForPathMustBeDirectory(t *testing.T) {
|
||||
tempFile, err := ioutil.TempFile("", "test-file")
|
||||
tempFile, err := os.CreateTemp("", "test-file")
|
||||
if err != nil {
|
||||
t.Errorf("error creating temporary file: %v", err)
|
||||
}
|
||||
defer os.Remove(tempFile.Name())
|
||||
|
||||
_, _, _, err = getPatchSetsFromPath(tempFile.Name(), testKnownTargets, ioutil.Discard)
|
||||
if err == nil {
|
||||
t.Fatalf("expected error for non-directory path %q", tempFile.Name())
|
||||
var pathErr *os.PathError
|
||||
if !errors.As(err, &pathErr) {
|
||||
t.Fatalf("expected os.PathError for non-directory path %q, but got %v", tempFile.Name(), err)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user