@@ -14,6 +14,7 @@ import (
1414 "sigs.k8s.io/kustomize/api/ifc"
1515 "sigs.k8s.io/kustomize/api/internal/git"
1616 "sigs.k8s.io/kustomize/kyaml/filesys"
17+ "sigs.k8s.io/kustomize/kyaml/testutil"
1718)
1819
1920func TestDefaultNewDirRepo (t * testing.T ) {
@@ -120,7 +121,8 @@ func TestLocFilePathColon(t *testing.T) {
120121
121122 // The colon is special because it was once used as the unix file separator.
122123 const url = "https://[2001:4860:4860::8888]/file.yaml"
123- const host = "2001:4860:4860::8888"
124+ // On Windows, colons are replaced with hyphens in IPv6 addresses
125+ const host = "2001-4860-4860--8888"
124126 const file = "file.yaml"
125127 req .Equal (simpleJoin (t , LocalizeDir , host , file ), locFilePath (url ))
126128
@@ -129,8 +131,10 @@ func TestLocFilePathColon(t *testing.T) {
129131
130132 // We check that we can create single directory, meaning ':' not used as file separator.
131133 req .NoError (fSys .Mkdir (targetDir ))
132- _ , err := fSys .Create (simpleJoin (t , targetDir , file ))
134+ f , err := fSys .Create (simpleJoin (t , targetDir , file ))
133135 req .NoError (err )
136+ // Close the file immediately to avoid file locking issues on Windows
137+ req .NoError (f .Close ())
134138
135139 // We check that the directory with such name is readable.
136140 files , err := fSys .ReadDir (targetDir )
@@ -139,6 +143,9 @@ func TestLocFilePathColon(t *testing.T) {
139143}
140144
141145func TestLocFilePath_SpecialChar (t * testing.T ) {
146+ // Skip on Windows as asterisk is invalid in Windows paths
147+ testutil .SkipWindows (t )
148+
142149 req := require .New (t )
143150
144151 // The wild card character is one of the legal uri characters with more meaning
@@ -163,19 +170,26 @@ func TestLocFilePath_SpecialFiles(t *testing.T) {
163170 for name , tFSys := range map [string ]struct {
164171 urlPath string
165172 pathDir , pathFile string
173+ skipWindows bool // Skip this test case on Windows
166174 }{
167175 "windows_reserved_name" : {
168176 urlPath : "/aux/file" ,
169177 pathDir : "aux" ,
170178 pathFile : "file" ,
171179 },
172180 "hidden_files" : {
173- urlPath : "/.../.file" ,
174- pathDir : "..." ,
175- pathFile : ".file" ,
181+ urlPath : "/.../.file" ,
182+ pathDir : "..." ,
183+ pathFile : ".file" ,
184+ skipWindows : true , // Windows treats "..." specially
176185 },
177186 } {
178187 t .Run (name , func (t * testing.T ) {
188+ // Skip Windows-incompatible tests
189+ if tFSys .skipWindows {
190+ testutil .SkipWindows (t )
191+ }
192+
179193 req := require .New (t )
180194
181195 expectedPath := simpleJoin (t , LocalizeDir , "host" , tFSys .pathDir , tFSys .pathFile )
@@ -304,23 +318,41 @@ func TestLocRootPath_SymlinkPath(t *testing.T) {
304318
305319func TestCleanedRelativePath (t * testing.T ) {
306320 fSys := filesys .MakeFsInMemory ()
307- require .NoError (t , fSys .MkdirAll ("/root/test" ))
308- require .NoError (t , fSys .WriteFile ("/root/test/file.yaml" , []byte ("" )))
309- require .NoError (t , fSys .WriteFile ("/root/filetwo.yaml" , []byte ("" )))
321+ // Use platform-appropriate root path
322+ rootPath := string (filepath .Separator ) + "root"
323+ testPath := filepath .Join (rootPath , "test" )
324+
325+ require .NoError (t , fSys .MkdirAll (testPath ))
326+ require .NoError (t , fSys .WriteFile (filepath .Join (testPath , "file.yaml" ), []byte ("" )))
327+ require .NoError (t , fSys .WriteFile (filepath .Join (rootPath , "filetwo.yaml" ), []byte ("" )))
310328
311329 // Absolute path is cleaned to relative path
312- cleanedPath := cleanedRelativePath (fSys , "/root/" , "/root/test/file.yaml" )
313- require .Equal (t , "test/file.yaml" , cleanedPath )
330+ cleanedPath := cleanedRelativePath (
331+ fSys ,
332+ filesys .ConfirmedDir (rootPath + string (filepath .Separator )),
333+ filepath .Join (testPath , "file.yaml" ))
334+ require .Equal (t , filepath .Join ("test" , "file.yaml" ), cleanedPath )
314335
315336 // Winding absolute path is cleaned to relative path
316- cleanedPath = cleanedRelativePath (fSys , "/root/" , "/root/test/../filetwo.yaml" )
337+ windingPath := filepath .Join (rootPath , "test" , ".." , "filetwo.yaml" )
338+ cleanedPath = cleanedRelativePath (
339+ fSys ,
340+ filesys .ConfirmedDir (rootPath + string (filepath .Separator )),
341+ windingPath )
317342 require .Equal (t , "filetwo.yaml" , cleanedPath )
318343
319344 // Already clean relative path stays the same
320- cleanedPath = cleanedRelativePath (fSys , "/root/" , "test/file.yaml" )
321- require .Equal (t , "test/file.yaml" , cleanedPath )
345+ cleanedPath = cleanedRelativePath (
346+ fSys ,
347+ filesys .ConfirmedDir (rootPath + string (filepath .Separator )),
348+ filepath .Join ("test" , "file.yaml" ))
349+ require .Equal (t , filepath .Join ("test" , "file.yaml" ), cleanedPath )
322350
323351 // Winding relative path is cleaned
324- cleanedPath = cleanedRelativePath (fSys , "/root/" , "test/../filetwo.yaml" )
352+ windingRelPath := filepath .Join ("test" , ".." , "filetwo.yaml" )
353+ cleanedPath = cleanedRelativePath (
354+ fSys ,
355+ filesys .ConfirmedDir (rootPath + string (filepath .Separator )),
356+ windingRelPath )
325357 require .Equal (t , "filetwo.yaml" , cleanedPath )
326358}
0 commit comments