This repository has been archived by the owner on Apr 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
utils_test.go
92 lines (85 loc) · 1.71 KB
/
utils_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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package skynet
import (
"net/url"
"testing"
)
var (
portalURL = DefaultPortalURL()
)
// TestMakeURL tests making URLs.
func TestMakeURL(t *testing.T) {
values1 := url.Values{}
values2 := url.Values{}
values2.Set("foo", "bar")
values2.Set("bar", "foo")
tests := []struct {
url, path, extraPath string
values url.Values
out string
}{
{
portalURL, "test", "",
nil,
portalURL + "/test",
},
{
portalURL, "test", "skylink",
values1,
portalURL + "/test/skylink",
},
{
portalURL, "/", "",
nil,
portalURL + "/",
},
{
portalURL, "/", "skylink",
nil,
portalURL + "/skylink",
},
{
portalURL + "/test", "skylink", "",
nil,
portalURL + "/test/skylink",
},
{
portalURL, "skynet/skyfile", "",
values2,
portalURL + "/skynet/skyfile?bar=foo&foo=bar",
},
{
portalURL, "//test/", "",
values2,
portalURL + "/test/?bar=foo&foo=bar",
},
}
for _, test := range tests {
url := makeURL(test.url, test.path, test.extraPath, test.values)
if url != test.out {
t.Fatalf("expected %v, got %v", test.out, url)
}
}
}
// TestWalkDirectory tests directory walking.
func TestWalkDirectory(t *testing.T) {
const testDir = "testdata"
files, err := walkDirectory(testDir)
if err != nil {
t.Error(err)
}
expectedFiles := []string{
"testdata/dir1/file3.txt",
"testdata/file1.txt",
"testdata/file2.txt",
"testdata/index.html",
"testdata/indexhtml",
}
if len(files) != len(expectedFiles) {
t.Errorf("expected %v files, got %v", len(expectedFiles), len(files))
}
for i, f := range files {
if f != expectedFiles[i] {
t.Errorf("file %s at index %d != expected file %s at same index", f, i, expectedFiles[i])
}
}
}