/
datasources_merge_test.go
73 lines (59 loc) · 2.35 KB
/
datasources_merge_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
//+build integration
package integration
import (
"net"
"net/http"
. "gopkg.in/check.v1"
"github.com/gotestyourself/gotestyourself/fs"
"github.com/gotestyourself/gotestyourself/icmd"
)
type MergeDatasourceSuite struct {
tmpDir *fs.Dir
l *net.TCPListener
}
var _ = Suite(&MergeDatasourceSuite{})
func (s *MergeDatasourceSuite) SetUpSuite(c *C) {
s.tmpDir = fs.NewDir(c, "gomplate-inttests",
fs.WithFiles(map[string]string{
"config.json": `{"foo": {"bar": "baz"}, "isDefault": false, "isOverride": true}`,
"default.yml": "foo:\n bar: qux\nother: true\nisDefault: true\nisOverride: false\n",
}),
)
var err error
s.l, err = net.ListenTCP("tcp", &net.TCPAddr{IP: net.ParseIP("127.0.0.1")})
handle(c, err)
http.HandleFunc("/foo.json", typeHandler("application/json", `{"foo": "bar"}`))
http.HandleFunc("/1.env", typeHandler("application/x-env", "FOO=1\nBAR=2\n"))
http.HandleFunc("/2.env", typeHandler("application/x-env", "FOO=3\n"))
go http.Serve(s.l, nil)
}
func (s *MergeDatasourceSuite) TearDownSuite(c *C) {
s.l.Close()
s.tmpDir.Remove()
}
func (s *MergeDatasourceSuite) TestMergeDatasource(c *C) {
result := icmd.RunCommand(GomplateBin,
"-d", "user="+s.tmpDir.Join("config.json"),
"-d", "default="+s.tmpDir.Join("default.yml"),
"-d", "config=merge:user|default",
"-i", `{{ ds "config" | toJSON }}`,
)
result.Assert(c, icmd.Expected{ExitCode: 0, Out: `{"foo":{"bar":"baz"},"isDefault":false,"isOverride":true,"other":true}`})
result = icmd.RunCommand(GomplateBin,
"-d", "default="+s.tmpDir.Join("default.yml"),
"-d", "config=merge:user|default",
"-i", `{{ defineDatasource "user" `+"`"+s.tmpDir.Join("config.json")+"`"+` }}{{ ds "config" | toJSON }}`,
)
result.Assert(c, icmd.Expected{ExitCode: 0, Out: `{"foo":{"bar":"baz"},"isDefault":false,"isOverride":true,"other":true}`})
result = icmd.RunCommand(GomplateBin,
"-d", "default="+s.tmpDir.Join("default.yml"),
"-d", "config=merge:http://"+s.l.Addr().String()+"/foo.json|default",
"-i", `{{ ds "config" | toJSON }}`,
)
result.Assert(c, icmd.Expected{ExitCode: 0, Out: `{"foo":"bar","isDefault":true,"isOverride":false,"other":true}`})
result = icmd.RunCommand(GomplateBin,
"-c", "merged=merge:http://"+s.l.Addr().String()+"/2.env|http://"+s.l.Addr().String()+"/1.env",
"-i", `FOO is {{ .merged.FOO }}`,
)
result.Assert(c, icmd.Expected{ExitCode: 0, Out: `FOO is 3`})
}