Skip to content

Commit 70b8351

Browse files
committed
test(param): add test cases
1 parent f4c68c5 commit 70b8351

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed

src/param/objUtil_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package param
2+
3+
import "testing"
4+
5+
func TestEntriesToUsers(t *testing.T) {
6+
entries := []string{
7+
":pass1",
8+
"user2:",
9+
"user3:pass3",
10+
}
11+
users := EntriesToUsers(entries)
12+
if len(users) != 3 {
13+
t.Fatal("user count is not 3")
14+
}
15+
if users[0].Username != "" {
16+
t.Fail()
17+
}
18+
if users[0].Password != "pass1" {
19+
t.Fail()
20+
}
21+
if users[1].Username != "user2" {
22+
t.Fail()
23+
}
24+
if users[1].Password != "" {
25+
t.Fail()
26+
}
27+
if users[2].Username != "user3" {
28+
t.Fail()
29+
}
30+
if users[2].Password != "pass3" {
31+
t.Fail()
32+
}
33+
}

src/param/strUtil_test.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package param
2+
3+
import "testing"
4+
5+
func TestSplitMapping(t *testing.T) {
6+
var k, v string
7+
var ok bool
8+
9+
k, v, ok = splitMapping("")
10+
if ok {
11+
t.Error("empty string should not OK")
12+
}
13+
14+
k, v, ok = splitMapping(":")
15+
if ok {
16+
t.Error("separator-only string should not OK")
17+
}
18+
19+
k, v, ok = splitMapping("::world")
20+
if ok {
21+
t.Error("empty key should not OK")
22+
}
23+
24+
k, v, ok = splitMapping(":hello:")
25+
if ok {
26+
t.Error("empty value should not OK")
27+
}
28+
29+
k, v, ok = splitMapping(":key:value")
30+
if !ok {
31+
t.Fail()
32+
}
33+
if k != "key" {
34+
t.Fail()
35+
}
36+
if v != "value" {
37+
t.Fail()
38+
}
39+
}
40+
41+
func TestNormalizePathMaps(t *testing.T) {
42+
maps := normalizePathMaps([]string{":/data/lib://usr/lib"})
43+
if maps["/data/lib"] != "/usr/lib" {
44+
t.Error(maps)
45+
}
46+
}
47+
48+
func TestNormalizeFilenames(t *testing.T) {
49+
files := []string{"", "abc/def.txt", "hello.txt"}
50+
normalized := normalizeFilenames(files)
51+
if len(normalized) != 1 || normalized[0] != "hello.txt" {
52+
t.Fail()
53+
}
54+
}

0 commit comments

Comments
 (0)