This repository has been archived by the owner on Jul 25, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathintegration_test.go
109 lines (87 loc) · 2.23 KB
/
integration_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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package urknall
import (
"sort"
"testing"
"github.com/dynport/urknall/utils"
)
type BuildHost struct {
}
func (b *BuildHost) Render(p Package) {
p.AddTemplate("staging", &Staging{})
}
type Staging struct {
RubyVersion string `urknall:"default=2.1.2"`
}
func (s *Staging) Render(p Package) {
p.AddTemplate("ruby-{{ .RubyVersion }}", &Ruby{Version: s.RubyVersion})
p.AddTemplate("es", &ElasticSearch{})
}
type Ruby struct {
Version string
}
type ElasticSearch struct {
}
func (e *ElasticSearch) Render(p Package) {
p.AddCommands("install", &testCommand{cmd: "apt-get install elasticsearch"})
p.AddTemplate("ruby", &Ruby{})
}
type testCommand struct {
cmd string
}
func (c *testCommand) Shell() string {
return c.cmd
}
func (c *testCommand) Logging() string {
return c.cmd
}
func (c *testCommand) Render(i interface{}) {
c.cmd = utils.MustRenderTemplate(c.cmd, i)
}
func (r *Ruby) Render(p Package) {
t := NewTask()
t.Add("apt-get update", "apt-get install ruby -v {{ .Version }}")
p.AddTask("install", t)
p.AddCommands("config", &testCommand{cmd: "echo {{ .Version }}"})
}
func rcover(t *testing.T) {
if r := recover(); r != nil {
t.Fatal(r)
}
}
func TestIntegration(t *testing.T) {
bh := &BuildHost{}
p, e := renderTemplate(bh)
if e != nil {
t.Errorf("didn't expect an error")
}
if p == nil {
t.Errorf("didn't expect the template to be nil")
}
names := []string{}
tasks := map[string]Task{}
for _, task := range p.tasks {
tasks[task.name] = task
names = append(names, task.name)
}
sort.Strings(names)
if len(names) != 5 {
t.Errorf("expected 5 names, got %d", len(names))
}
tt := []string{"staging.es.install", "staging.es.ruby.config", "staging.es.ruby.install", "staging.ruby-2.1.2.config", "staging.ruby-2.1.2.install"}
for i := range tt {
if names[i] != tt[i] {
t.Errorf("expected names[%d] = %q, got %q", i, tt[i], names[i])
}
}
task := tasks["staging.ruby-2.1.2.config"]
commands, e := task.Commands()
if e != nil {
t.Errorf("didn't expect an error, got %s", e)
}
if len(commands) != 1 {
t.Errorf("expected to find 1 command, got %d", len(commands))
}
if commands[0].Shell() != "echo 2.1.2" {
t.Errorf("expected first command to be %q, got %q", "echo 2.1.2", commands[0].Shell())
}
}