-
Notifications
You must be signed in to change notification settings - Fork 0
/
conf_test.go
77 lines (65 loc) · 1.64 KB
/
conf_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 main
import (
"io/ioutil"
"net/url"
"testing"
)
func TestParseConf(t *testing.T) {
expectVar := map[string]string{
"base_path": "/data/apt-mirror",
"mirror_path": "/data/apt-mirror/mirror",
"skel_path": "/data/apt-mirror/skel",
"nthreads": "5",
"defaultarch": "myarch",
"translations": "en zh_TW",
}
str, err := ioutil.ReadFile("conf.sample")
if err != nil {
t.Fatalf("Cannot read config sample from filesystem: %s", err)
}
cfg, err := ParseConfig(string(str))
if err != nil {
t.Fatalf("Parse error: %s", err)
}
for k, v := range expectVar {
if cfg.Variables[k] != v {
t.Errorf("Expected var %#v is %#v, got %#v", k, v, cfg.Variables[k])
}
}
if len(cfg.Repositories) != 4 {
t.Errorf("Expected 4 repositories, got %d", len(cfg.Repositories))
}
if len(cfg.Clean) != 2 {
t.Errorf("Expected 2 clean, got %d", len(cfg.Clean))
}
}
func TestPath(t *testing.T) {
str, err := ioutil.ReadFile("conf.sample")
if err != nil {
t.Fatalf("Cannot read config sample from filesystem: %s", err)
}
cfg, err := ParseConfig(string(str))
if err != nil {
t.Fatalf("Parse error: %s", err)
}
urls := []string{
"example.com/debian",
"example.com/debian/",
}
for _, uri := range urls {
u, err := url.Parse("http://" + uri)
if err != nil {
t.Fatalf("Cannot parse url %s: %s", uri, err)
}
expect := "/data/apt-mirror/mirror" + "/" + uri
actual := cfg.MirrorPath(u)
if actual != expect {
t.Errorf("Expected %s, got %s", expect, actual)
}
expect = "/data/apt-mirror/skel" + "/" + uri
actual = cfg.SkelPath(u)
if actual != expect {
t.Errorf("Expected %s, got %s", expect, actual)
}
}
}