/
config_test.go
60 lines (57 loc) · 1.36 KB
/
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
package main
import (
"io/ioutil"
"os"
"testing"
)
const testConfigFile = "/tmp/test-config.yml"
func TestLoadConfig(t *testing.T) {
config := `directory: /tmp
status: /tmp/repo-hash.yml
email:
smtp-host: smtp.example.com:25
recipient: nobody@nowhere.com
sender: nobody@nowhere.com
success: true
once: true
modules:
- name: continuum
url: git@github.com:c4s4/continuum.git
command: |
set -e
make test`
ioutil.WriteFile(testConfigFile, []byte(config), 0666)
defer os.Remove(testConfigFile)
expected := Config{
Directory: "/tmp",
Status: "/tmp/repo-hash.yml",
Email: EmailConfig{
SmtpHost: "smtp.example.com:25",
Recipient: "nobody@nowhere.com",
Sender: "nobody@nowhere.com",
Success: true,
Once: true,
},
Modules: []ModuleConfig{
{
Name: "continuum",
Url: "git@github.com:c4s4/continuum.git",
Command: "set -e\nmake test",
},
},
}
actual := LoadConfig(testConfigFile)
if expected.Directory != actual.Directory ||
expected.Email != actual.Email ||
expected.Status != actual.Status {
t.Error("Broken configuration loader")
}
if len(expected.Modules) != len(actual.Modules) {
t.Error("Broken configuration loader")
}
for i := 0; i < len(expected.Modules); i++ {
if expected.Modules[i] != actual.Modules[i] {
t.Error("Broken configuration loader")
}
}
}