-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathconfig_test.go
61 lines (53 loc) · 1015 Bytes
/
config_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
package main
import (
"io/ioutil"
"os"
"testing"
)
func TestNewConfig(t *testing.T) {
f, err := ioutil.TempFile("", "")
if err != nil {
t.Error(err)
}
defer func() {
f.Close()
os.Remove(f.Name())
}()
data := `---
host:
webapi: localhost
reverse_proxy_suffix: .dev.example.net
listen:
foreign_address: 127.0.0.1
http:
- listen: 8080
target: 5000
docker:
endpoint: unix:///var/run/docker.sock
storage:
datadir: ./data
htmldir: ./html
parameters:
- name: branch
env: GIT_BRANCH
rule: "[0-9a-z-]{32}"
required: true
- name: nick
env: NICK
rule: "[0-9A-Za-z]{10}"
required: false
`
if err := ioutil.WriteFile(f.Name(), []byte(data), 0644); err != nil {
t.Error(err)
}
cfg := NewConfig(f.Name())
if cfg.Parameter[0].Name != "branch" {
t.Error("could not parse parameter")
}
if cfg.Parameter[1].Env != "NICK" {
t.Error("could not parse parameter")
}
if cfg.Parameter[0].Required != true {
t.Error("could not parse parameter")
}
}