@@ -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
@@ -139,6 +141,9 @@ func TestLocFilePathColon(t *testing.T) {
139141}
140142
141143func TestLocFilePath_SpecialChar (t * testing.T ) {
144+ // Skip on Windows as asterisk is invalid in Windows paths
145+ testutil .SkipWindows (t )
146+
142147 req := require .New (t )
143148
144149 // The wild card character is one of the legal uri characters with more meaning
@@ -163,19 +168,26 @@ func TestLocFilePath_SpecialFiles(t *testing.T) {
163168 for name , tFSys := range map [string ]struct {
164169 urlPath string
165170 pathDir , pathFile string
171+ skipWindows bool // Skip this test case on Windows
166172 }{
167173 "windows_reserved_name" : {
168174 urlPath : "/aux/file" ,
169175 pathDir : "aux" ,
170176 pathFile : "file" ,
171177 },
172178 "hidden_files" : {
173- urlPath : "/.../.file" ,
174- pathDir : "..." ,
175- pathFile : ".file" ,
179+ urlPath : "/.../.file" ,
180+ pathDir : "..." ,
181+ pathFile : ".file" ,
182+ skipWindows : true , // Windows treats "..." specially
176183 },
177184 } {
178185 t .Run (name , func (t * testing.T ) {
186+ // Skip Windows-incompatible tests
187+ if tFSys .skipWindows {
188+ testutil .SkipWindows (t )
189+ }
190+
179191 req := require .New (t )
180192
181193 expectedPath := simpleJoin (t , LocalizeDir , "host" , tFSys .pathDir , tFSys .pathFile )
@@ -304,23 +316,27 @@ func TestLocRootPath_SymlinkPath(t *testing.T) {
304316
305317func TestCleanedRelativePath (t * testing.T ) {
306318 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 ("" )))
319+ // Use platform-appropriate root path
320+ rootPath := string (filepath .Separator ) + "root"
321+ testPath := rootPath + string (filepath .Separator ) + "test"
322+
323+ require .NoError (t , fSys .MkdirAll (testPath ))
324+ require .NoError (t , fSys .WriteFile (testPath + string (filepath .Separator )+ "file.yaml" , []byte ("" )))
325+ require .NoError (t , fSys .WriteFile (rootPath + string (filepath .Separator )+ "filetwo.yaml" , []byte ("" )))
310326
311327 // Absolute path is cleaned to relative path
312- cleanedPath := cleanedRelativePath (fSys , "/root/" , "/root/test/ file.yaml" )
313- require .Equal (t , "test/ file.yaml" , cleanedPath )
328+ cleanedPath := cleanedRelativePath (fSys , filesys . ConfirmedDir ( rootPath + string ( filepath . Separator )), testPath + string ( filepath . Separator ) + " file.yaml" )
329+ require .Equal (t , filepath . Join ( "test" , " file.yaml") , cleanedPath )
314330
315331 // Winding absolute path is cleaned to relative path
316- cleanedPath = cleanedRelativePath (fSys , "/root/" , "/root/ test/../ filetwo.yaml" )
332+ cleanedPath = cleanedRelativePath (fSys , filesys . ConfirmedDir ( rootPath + string ( filepath . Separator )), rootPath + string ( filepath . Separator ) + " test" + string ( filepath . Separator ) + ".." + string ( filepath . Separator ) + " filetwo.yaml" )
317333 require .Equal (t , "filetwo.yaml" , cleanedPath )
318334
319335 // Already clean relative path stays the same
320- cleanedPath = cleanedRelativePath (fSys , "/root/" , "test/ file.yaml" )
321- require .Equal (t , "test/ file.yaml" , cleanedPath )
336+ cleanedPath = cleanedRelativePath (fSys , filesys . ConfirmedDir ( rootPath + string ( filepath . Separator )) , "test" + string ( filepath . Separator ) + " file.yaml" )
337+ require .Equal (t , filepath . Join ( "test" , " file.yaml") , cleanedPath )
322338
323339 // Winding relative path is cleaned
324- cleanedPath = cleanedRelativePath (fSys , "/root/" , "test/../ filetwo.yaml" )
340+ cleanedPath = cleanedRelativePath (fSys , filesys . ConfirmedDir ( rootPath + string ( filepath . Separator )) , "test" + string ( filepath . Separator ) + ".." + string ( filepath . Separator ) + " filetwo.yaml" )
325341 require .Equal (t , "filetwo.yaml" , cleanedPath )
326342}
0 commit comments