-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig_test.go
83 lines (75 loc) · 1.6 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package main
import (
"fmt"
"testing"
toml "github.com/pelletier/go-toml"
"github.com/stretchr/testify/assert"
)
var out = `
[[process]]
cmd = "nginx -V -E"
[process.config]
src = "source.tmpl"
dst = "target.tmpl"
[process.config.data]
domain = "test.tld"
[[process]]
cmd = "php -v"
[process.config]
src = "source.tmpl"
dst = "target.tmpl"
[[process]]
cmd = "true -v"
`
func TestDefaultConfig(t *testing.T) {
c := Config{
PreStart: Command{
Command: "/bin/bash /provision/bin/initialize",
Template: Template{
Source: "source.tmpl",
Target: "target.tmpl",
},
},
Cron: []Cron{
{
Command: Command{
Command: "echo tick",
},
Schedule: "@every 5s",
}},
Process: []Command{
{
Command: "nginx -V -E",
Template: Template{
Source: "source.tmpl",
Target: "target.tmpl",
Context: map[string]string{
"domain": "test.tld",
},
},
},
{
Command: "php -v",
Template: Template{
Source: "source.tmpl",
Target: "target.tmpl",
},
},
{
Command: "true -v",
},
},
}
err := toml.Unmarshal([]byte(out), &Config{})
assert.NoError(t, err)
out, err := toml.Marshal(c)
fmt.Println(string(out))
assert.NoError(t, err)
assert.Contains(t, string(out), `src = "source.tmpl"`)
assert.Contains(t, string(out), `dst = "target.tmpl"`)
assert.Contains(t, string(out), `cmd = "nginx -V -E"`)
assert.Contains(t, string(out), `cmd = "php -v"`)
assert.Contains(t, string(out), `[process.config]`)
assert.Contains(t, string(out), `[pre_start]`)
assert.Contains(t, string(out), `[cron.job]`)
}