-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfuncs_test.go
77 lines (70 loc) · 2.78 KB
/
funcs_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package patrol
import (
"fmt"
"log"
"sabey.co/unittest"
"testing"
)
func TestFuncs(t *testing.T) {
log.Println("TestFuncs")
fmt.Println("IsAppServiceID")
unittest.Equals(t, IsAppServiceID(""), false)
unittest.Equals(t, IsAppServiceID("."), false)
unittest.Equals(t, IsAppServiceID(".."), false)
unittest.Equals(t, IsAppServiceID("-"), false)
unittest.Equals(t, IsAppServiceID("a-"), false)
unittest.Equals(t, IsAppServiceID("-a"), false)
unittest.Equals(t, IsAppServiceID("a-a"), true)
unittest.Equals(t, IsAppServiceID("a--a"), true)
unittest.Equals(t, IsAppServiceID("123456789012345679012345678901234567890123456789012345678901234"), true)
unittest.Equals(t, IsAppServiceID("1234567890123456790123456789012345678901234567890123456789012345"), false)
for i := 0; i <= 0x7F; i++ {
if i >= '0' && i <= '9' ||
i >= 'A' && i <= 'Z' ||
i >= 'a' && i <= 'z' {
unittest.Equals(t, IsAppServiceID(string([]byte{byte(i)})), true)
} else {
unittest.Equals(t, IsAppServiceID(string([]byte{byte(i)})), false)
}
}
fmt.Println("IsPathClean")
// invalid
unittest.Equals(t, IsPathClean(""), false)
unittest.Equals(t, IsPathClean("."), false)
unittest.Equals(t, IsPathClean("./"), false)
unittest.Equals(t, IsPathClean("a/."), false)
unittest.Equals(t, IsPathClean("a/.."), false)
unittest.Equals(t, IsPathClean("a/./"), false)
unittest.Equals(t, IsPathClean("a/../"), false)
unittest.Equals(t, IsPathClean("../a/."), false)
unittest.Equals(t, IsPathClean("../a/./"), false)
unittest.Equals(t, IsPathClean("../a/.."), false)
unittest.Equals(t, IsPathClean("../a/../"), false)
unittest.Equals(t, IsPathClean("a/../b/c"), false)
unittest.Equals(t, IsPathClean("a/b/../c"), false)
unittest.Equals(t, IsPathClean("/."), false)
unittest.Equals(t, IsPathClean("/.."), false)
unittest.Equals(t, IsPathClean("/./"), false)
unittest.Equals(t, IsPathClean("/../"), false)
// invalid - multiple delimiters
// filepath.Clean doesn't like multiple /, such as //
// the reason for this is that this is for paths not URIs
unittest.Equals(t, IsPathClean(".//"), false)
unittest.Equals(t, IsPathClean("..//"), false)
unittest.Equals(t, IsPathClean("..///"), false)
// this is invalid because // gets cleaned to /
unittest.Equals(t, IsPathClean("//"), false)
unittest.Equals(t, IsPathClean("///"), false)
// valid
unittest.Equals(t, IsPathClean("/"), true)
// relative paths are allowed
unittest.Equals(t, IsPathClean("a"), true)
unittest.Equals(t, IsPathClean("a/"), true)
unittest.Equals(t, IsPathClean("a/b"), true)
unittest.Equals(t, IsPathClean("a/b/"), true)
unittest.Equals(t, IsPathClean("a/b/c"), true)
unittest.Equals(t, IsPathClean(".."), true)
unittest.Equals(t, IsPathClean("../"), true)
unittest.Equals(t, IsPathClean("../a"), true)
unittest.Equals(t, IsPathClean("../a/"), true)
}