Skip to content

Commit 0210ca4

Browse files
committed
test: adjust test logic to suit for Windows platform
1 parent e60cbf4 commit 0210ca4

File tree

3 files changed

+33
-10
lines changed

3 files changed

+33
-10
lines changed

src/param/helper_test.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package param
33
import (
44
"mjpclab.dev/ghfs/src/util"
55
"path/filepath"
6+
"runtime"
67
"testing"
78
)
89

@@ -89,17 +90,29 @@ func TestNormalizePathMaps(t *testing.T) {
8990
t.Error(results)
9091
}
9192
fsPath, _ = filepath.Abs("/usr/lib")
92-
if !expectStrings(results[0][:], "/data/lib", fsPath) {
93-
t.Error(results[0])
93+
if runtime.GOOS == "windows" {
94+
if !expectStrings(results[0][:], "/data/lib", `\\usr\lib`) {
95+
t.Error(results[0])
96+
}
97+
} else {
98+
if !expectStrings(results[0][:], "/data/lib", fsPath) {
99+
t.Error(results[0])
100+
}
94101
}
95102

96103
results, _ = normalizePathMaps([][2]string{{"/data/lib", "//usr/lib"}, {"foo", "bar/baz"}})
97104
if len(results) != 2 {
98105
t.Error(results)
99106
}
100107
fsPath, _ = filepath.Abs("/usr/lib")
101-
if !expectStrings(results[0][:], "/data/lib", fsPath) {
102-
t.Error(results[0])
108+
if runtime.GOOS == "windows" {
109+
if !expectStrings(results[0][:], "/data/lib", `\\usr\lib`) {
110+
t.Error(results[0])
111+
}
112+
} else {
113+
if !expectStrings(results[0][:], "/data/lib", fsPath) {
114+
t.Error(results[0])
115+
}
103116
}
104117
fsPath, _ = filepath.Abs("bar/baz")
105118
if !expectStrings(results[1][:], "/foo", fsPath) {

src/serverHandler/alias_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package serverHandler
22

3-
import "testing"
3+
import (
4+
"runtime"
5+
"testing"
6+
)
47

58
func TestAlias(t *testing.T) {
69
alias := createAlias("/hello/world/foo", "/tmp")
@@ -10,7 +13,7 @@ func TestAlias(t *testing.T) {
1013
t.Error()
1114
}
1215

13-
if alias.isMatch("/Hello/world/foo") {
16+
if alias.isMatch("/Hello/world/foo") != (runtime.GOOS == "windows") {
1417
t.Error()
1518
}
1619

@@ -35,7 +38,7 @@ func TestAlias(t *testing.T) {
3538
t.Error()
3639
}
3740

38-
if alias.isSuccessorOf("/HELLO/world/") {
41+
if alias.isSuccessorOf("/HELLO/world/") != (runtime.GOOS == "windows") {
3942
t.Error()
4043
}
4144

src/util/wildcard_test.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
package util
22

3-
import "testing"
3+
import (
4+
"runtime"
5+
"testing"
6+
)
47

58
func TestWildcardToStrRegexp(t *testing.T) {
69
wildcard := "file.{name}*.txt"
710
regexp := WildcardToStrRegexp(wildcard)
8-
if regexp != `^file\.\{name\}.*?\.txt$` {
9-
t.Error(regexp)
11+
expected := `^file\.\{name\}.*?\.txt$`
12+
if runtime.GOOS == "windows" {
13+
expected = "(?i)" + expected
14+
}
15+
if regexp != expected {
16+
t.Error(regexp + " <= " + expected)
1017
}
1118
}

0 commit comments

Comments
 (0)