@@ -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 ) {
@@ -139,6 +140,9 @@ func TestLocFilePathColon(t *testing.T) {
139140}
140141
141142func TestLocFilePath_SpecialChar (t * testing.T ) {
143+ // Skip on Windows as asterisk is invalid in Windows paths
144+ testutil .SkipWindows (t )
145+
142146 req := require .New (t )
143147
144148 // The wild card character is one of the legal uri characters with more meaning
@@ -163,19 +167,26 @@ func TestLocFilePath_SpecialFiles(t *testing.T) {
163167 for name , tFSys := range map [string ]struct {
164168 urlPath string
165169 pathDir , pathFile string
170+ skipWindows bool // Skip this test case on Windows
166171 }{
167172 "windows_reserved_name" : {
168173 urlPath : "/aux/file" ,
169174 pathDir : "aux" ,
170175 pathFile : "file" ,
171176 },
172177 "hidden_files" : {
173- urlPath : "/.../.file" ,
174- pathDir : "..." ,
175- pathFile : ".file" ,
178+ urlPath : "/.../.file" ,
179+ pathDir : "..." ,
180+ pathFile : ".file" ,
181+ skipWindows : true , // Windows treats "..." specially
176182 },
177183 } {
178184 t .Run (name , func (t * testing.T ) {
185+ // Skip Windows-incompatible tests
186+ if tFSys .skipWindows {
187+ testutil .SkipWindows (t )
188+ }
189+
179190 req := require .New (t )
180191
181192 expectedPath := simpleJoin (t , LocalizeDir , "host" , tFSys .pathDir , tFSys .pathFile )
@@ -304,23 +315,27 @@ func TestLocRootPath_SymlinkPath(t *testing.T) {
304315
305316func TestCleanedRelativePath (t * testing.T ) {
306317 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 ("" )))
318+ // Use platform-appropriate root path
319+ rootPath := string (filepath .Separator ) + "root"
320+ testPath := rootPath + string (filepath .Separator ) + "test"
321+
322+ require .NoError (t , fSys .MkdirAll (testPath ))
323+ require .NoError (t , fSys .WriteFile (testPath + string (filepath .Separator )+ "file.yaml" , []byte ("" )))
324+ require .NoError (t , fSys .WriteFile (rootPath + string (filepath .Separator )+ "filetwo.yaml" , []byte ("" )))
310325
311326 // Absolute path is cleaned to relative path
312- cleanedPath := cleanedRelativePath (fSys , "/root/" , "/root/test/ file.yaml" )
313- require .Equal (t , "test/ file.yaml" , cleanedPath )
327+ cleanedPath := cleanedRelativePath (fSys , filesys . ConfirmedDir ( rootPath + string ( filepath . Separator )), testPath + string ( filepath . Separator ) + " file.yaml" )
328+ require .Equal (t , filepath . Join ( "test" , " file.yaml") , cleanedPath )
314329
315330 // Winding absolute path is cleaned to relative path
316- cleanedPath = cleanedRelativePath (fSys , "/root/" , "/root/ test/../ filetwo.yaml" )
331+ cleanedPath = cleanedRelativePath (fSys , filesys . ConfirmedDir ( rootPath + string ( filepath . Separator )), rootPath + string ( filepath . Separator ) + " test" + string ( filepath . Separator ) + ".." + string ( filepath . Separator ) + " filetwo.yaml" )
317332 require .Equal (t , "filetwo.yaml" , cleanedPath )
318333
319334 // Already clean relative path stays the same
320- cleanedPath = cleanedRelativePath (fSys , "/root/" , "test/ file.yaml" )
321- require .Equal (t , "test/ file.yaml" , cleanedPath )
335+ cleanedPath = cleanedRelativePath (fSys , filesys . ConfirmedDir ( rootPath + string ( filepath . Separator )) , "test" + string ( filepath . Separator ) + " file.yaml" )
336+ require .Equal (t , filepath . Join ( "test" , " file.yaml") , cleanedPath )
322337
323338 // Winding relative path is cleaned
324- cleanedPath = cleanedRelativePath (fSys , "/root/" , "test/../ filetwo.yaml" )
339+ cleanedPath = cleanedRelativePath (fSys , filesys . ConfirmedDir ( rootPath + string ( filepath . Separator )) , "test" + string ( filepath . Separator ) + ".." + string ( filepath . Separator ) + " filetwo.yaml" )
325340 require .Equal (t , "filetwo.yaml" , cleanedPath )
326341}
0 commit comments