Skip to content

Commit b333572

Browse files
committed
Add a helper for checking not an absolute path err
1 parent efbbd41 commit b333572

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

pkg/operator/staticpod/file_utils_linux_test.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package staticpod
44

55
import (
66
"bytes"
7+
"fmt"
78
"os"
89
"path/filepath"
910
"testing"
@@ -105,7 +106,7 @@ func TestSwapDirectoriesAtomic(t *testing.T) {
105106
return dirA, dirB
106107
},
107108
checkResult: func(t *testing.T, dirA, dirB string, err error) {
108-
if err == nil || err.Error() != `not an absolute path: "a"` {
109+
if !checkAbsolutePathError(err, "a") {
109110
t.Errorf("Expected not an absolute path error, got %v", err)
110111
}
111112
},
@@ -118,7 +119,7 @@ func TestSwapDirectoriesAtomic(t *testing.T) {
118119
return dirA, dirB
119120
},
120121
checkResult: func(t *testing.T, dirA, dirB string, err error) {
121-
if err == nil || err.Error() != `not an absolute path: "b"` {
122+
if !checkAbsolutePathError(err, "b") {
122123
t.Errorf("Expected not an absolute path error, got %v", err)
123124
}
124125
},
@@ -133,6 +134,10 @@ func TestSwapDirectoriesAtomic(t *testing.T) {
133134
}
134135
}
135136

137+
func checkAbsolutePathError(err error, path string) bool {
138+
return err != nil && err.Error() == fmt.Sprintf("not an absolute path: %q", path)
139+
}
140+
136141
type fileState struct {
137142
Content []byte
138143
Perm os.FileMode

0 commit comments

Comments
 (0)