MCPcopy
hub / github.com/kptdev/kpt / TestIsInsideDirectory

Function TestIsInsideDirectory

internal/cmdexport/pathutil/pathutil_test.go:72–105  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

70}
71
72func TestIsInsideDirectory(t *testing.T) {
73 base := path.Join(os.TempDir(), "kpt-path-test")
74 file := path.Join(base, "temp-file")
75 dirWithSamePrefix := fmt.Sprintf("%s-surfix", base)
76 baseWithSeparator := fmt.Sprintf(
77 "%s%s",
78 base,
79 string(os.PathSeparator),
80 )
81
82 _, err := IsInsideDir("resources", ".")
83 assert.Error(t, err, "argument `path` (resources) is not an absolute path")
84 _, err = IsInsideDir("/resources", ".")
85 assert.Error(t, err, "argument `directory` (.) is not an absolute path")
86
87 result, err := IsInsideDir(path.Join(base, "."), base)
88 assert.NilError(t, err)
89 assert.Equal(t, result, true)
90 result, err = IsInsideDir(path.Join(base, "."), baseWithSeparator)
91 assert.NilError(t, err)
92 assert.Equal(t, result, true)
93 result, err = IsInsideDir(file, base)
94 assert.NilError(t, err)
95 assert.Equal(t, result, true)
96 result, err = IsInsideDir(file, baseWithSeparator)
97 assert.NilError(t, err)
98 assert.Equal(t, result, true)
99 result, err = IsInsideDir(path.Join(base, ".."), base)
100 assert.NilError(t, err)
101 assert.Equal(t, result, false)
102 result, err = IsInsideDir(dirWithSamePrefix, base)
103 assert.NilError(t, err)
104 assert.Equal(t, result, false)
105}

Callers

nothing calls this directly

Calls 2

IsInsideDirFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected