-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver_test.go
45 lines (37 loc) · 891 Bytes
/
server_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
package main
import (
"path/filepath"
"strings"
"testing"
)
var splitFn = func(c rune) bool {
return c == '/'
}
func TestParsePath(t *testing.T) {
path := "/foo/bar"
components := strings.FieldsFunc(path, splitFn)
if len(components) != 2 {
t.Fatalf("wrong size")
}
if components[0] != "foo" || components[1] != "bar" {
t.Fatalf("wrong content")
}
}
func TestGetDir(t *testing.T) {
dir := sampleCuePath()
testCases := []struct {
paths []string
expect string
}{
{paths: []string{"myapp", "prod"}, expect: "myapp/prod"},
{paths: []string{"myapp", "prod", "gibberish"}, expect: "myapp/prod"},
{paths: []string{"myapp"}, expect: "myapp"},
}
for _, testCase := range testCases {
idx := getDir(dir, testCase.paths)
got := filepath.Join(testCase.paths[0:idx]...)
if got != testCase.expect {
t.Fatalf("expect %v, got %v", testCase.expect, got)
}
}
}