@@ -14,6 +14,24 @@ import (
14
14
15
15
const windowsOS = "windows"
16
16
17
+ // only used for windows
18
+ var currentDriveLetter = getCurrentDrive ()
19
+
20
+ // get the current drive letter in lowercase on windows that the test is running
21
+ func getCurrentDrive () string {
22
+ if runtime .GOOS != windowsOS {
23
+ return ""
24
+ }
25
+ p , err := filepath .Abs ("/" )
26
+ if err != nil {
27
+ panic (err )
28
+ }
29
+ if len (p ) == 0 {
30
+ panic ("current windows drive letter is empty" )
31
+ }
32
+ return strings .ToLower (string (p [0 ]))
33
+ }
34
+
17
35
func TestNormalizer_NormalizeURI (t * testing.T ) {
18
36
type testNormalizePathsTestCases []struct {
19
37
refPath string
@@ -299,7 +317,7 @@ func TestNormalizer_NormalizeBase(t *testing.T) {
299
317
{
300
318
// path clean
301
319
Base : "///folder//subfolder///file.json/" ,
302
- Expected : "file:///c :/folder/subfolder/file.json" ,
320
+ Expected : "file:///" + currentDriveLetter + " :/folder/subfolder/file.json" ,
303
321
Windows : true ,
304
322
},
305
323
{
@@ -326,7 +344,7 @@ func TestNormalizer_NormalizeBase(t *testing.T) {
326
344
{
327
345
// handling dots (3/6): valid, cleaned to /c:/ on windows
328
346
Base : "/.." ,
329
- Expected : "file:///c :" ,
347
+ Expected : "file:///" + currentDriveLetter + " :" ,
330
348
Windows : true ,
331
349
},
332
350
{
@@ -359,7 +377,7 @@ func TestNormalizer_NormalizeBase(t *testing.T) {
359
377
// windows-only cases
360
378
{
361
379
Base : "/base/sub/file.json" ,
362
- Expected : "file:///c :/base/sub/file.json" , // on windows, filepath.Abs("/a/b") prepends the "c:" drive
380
+ Expected : "file:///" + currentDriveLetter + " :/base/sub/file.json" , // on windows, filepath.Abs("/a/b") prepends the "c:" drive
363
381
Windows : true ,
364
382
},
365
383
{
0 commit comments