forked from hashicorp/terraform-ls
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix volume case issue in windows platform (hashicorp#199)
* fix volume case issue in windows platform * update * add test case
- Loading branch information
Showing
5 changed files
with
106 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package rootmodule | ||
|
||
import ( | ||
"path/filepath" | ||
"strings" | ||
) | ||
|
||
func pathEquals(path1, path2 string) bool { | ||
volume1 := filepath.VolumeName(path1) | ||
volume2 := filepath.VolumeName(path2) | ||
return strings.EqualFold(volume1, volume2) && path1[len(volume1):] == path2[len(volume2):] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// +build !windows | ||
|
||
package rootmodule | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
) | ||
|
||
func TestPathEquals(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
path1 string | ||
path2 string | ||
expected bool | ||
}{ | ||
{ | ||
"path the same", | ||
`/home/user/documents/tf`, | ||
`/home/user/documents/tf`, | ||
true, | ||
}, | ||
{ | ||
"path case not the same", | ||
`/home/user/documents/tf`, | ||
`/Home/user/documents/tf`, | ||
false, | ||
}, | ||
} | ||
|
||
for i, tc := range testCases { | ||
t.Run(fmt.Sprintf("%d-%s", i, tc.name), func(t *testing.T) { | ||
result := pathEquals(tc.path1, tc.path2) | ||
if result != tc.expected { | ||
t.Fatalf("expected: %t Got: %t", tc.expected, result) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package rootmodule | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
) | ||
|
||
func TestPathEquals(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
path1 string | ||
path2 string | ||
expected bool | ||
}{ | ||
{ | ||
"file path the same", | ||
`c:\Users\user\Documents\tf`, | ||
`c:\Users\user\Documents\tf`, | ||
true, | ||
}, | ||
{ | ||
"volume case insensitive", | ||
`c:\Users\user\Documents\tf`, | ||
`C:\Users\user\Documents\tf`, | ||
true, | ||
}, | ||
{ | ||
"path folder case different", | ||
`c:\Users\user\Documents\tf`, | ||
`c:\Users\user\documents\tf`, | ||
false, | ||
}, | ||
{ | ||
"file path different", | ||
`c:\Users\user\Documents\tf`, | ||
`c:\Users\user\Documents\tf\test`, | ||
false, | ||
}, | ||
} | ||
|
||
for i, tc := range testCases { | ||
t.Run(fmt.Sprintf("%d-%s", i, tc.name), func(t *testing.T) { | ||
result := pathEquals(tc.path1, tc.path2) | ||
if result != tc.expected { | ||
t.Fatalf("expected: %t Got: %t", tc.expected, result) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters