Skip to content

Commit bdd0f5d

Browse files
committed
test: add Junction file type test on Windows
1 parent 976aefc commit bdd0f5d

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

staging/src/k8s.io/mount-utils/mount_windows_test.go

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
"testing"
2828

2929
"github.com/stretchr/testify/assert"
30-
"k8s.io/utils/exec/testing"
30+
testingexec "k8s.io/utils/exec/testing"
3131
)
3232

3333
func makeLink(link, target string) error {
@@ -193,7 +193,26 @@ func TestIsLikelyNotMountPoint(t *testing.T) {
193193
}
194194
return removeLink(targeLinkPath)
195195
},
196-
true,
196+
false,
197+
false,
198+
},
199+
{
200+
"junction",
201+
"targetDir",
202+
func(base, fileName, targetLinkName string) error {
203+
target := filepath.Join(base, targetLinkName)
204+
if err := os.Mkdir(target, 0o750); err != nil {
205+
return err
206+
}
207+
208+
// create a Junction file type on Windows
209+
junction := filepath.Join(base, fileName)
210+
if output, err := exec.Command("cmd", "/c", "mklink", "/J", junction, target).CombinedOutput(); err != nil {
211+
return fmt.Errorf("mklink failed: %v, link(%q) target(%q) output: %q", err, junction, target, string(output))
212+
}
213+
return nil
214+
},
215+
false,
197216
false,
198217
},
199218
}
@@ -207,7 +226,7 @@ func TestIsLikelyNotMountPoint(t *testing.T) {
207226

208227
filePath := filepath.Join(base, test.fileName)
209228
result, err := mounter.IsLikelyNotMountPoint(filePath)
210-
assert.Equal(t, result, test.expectedResult, "Expect result not equal with IsLikelyNotMountPoint(%s) return: %q, expected: %q",
229+
assert.Equal(t, test.expectedResult, result, "Expect result not equal with IsLikelyNotMountPoint(%s) return: %q, expected: %q",
211230
filePath, result, test.expectedResult)
212231

213232
if test.expectError {

0 commit comments

Comments
 (0)