forked from convox/rack
-
Notifications
You must be signed in to change notification settings - Fork 1
/
app_test.go
120 lines (104 loc) · 2.22 KB
/
app_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
110
111
112
113
114
115
116
117
118
119
120
package models_test
import (
"os"
"sort"
"testing"
"github.com/convox/rack/api/models"
"github.com/convox/rack/manifest"
"github.com/stretchr/testify/assert"
)
func init() {
os.Setenv("RACK", "convox-test")
}
func TestRackStackName(t *testing.T) {
r := models.App{
Name: "convox-test",
}
assert.Equal(t, "convox-test", r.StackName())
}
func TestAppStackName(t *testing.T) {
// unbound app (no rack prefix)
a := models.App{
Name: "httpd",
Tags: map[string]string{
"Type": "app",
"System": "convox",
"Rack": "convox-test",
},
}
assert.Equal(t, "httpd", a.StackName())
// bound app (rack prefix, and Name tag)
a = models.App{
Name: "httpd",
Tags: map[string]string{
"Name": "httpd",
"Type": "app",
"System": "convox",
"Rack": "convox-test",
},
}
assert.Equal(t, "convox-test-httpd", a.StackName())
}
func TestAppCronJobs(t *testing.T) {
m := manifest.Manifest{
Version: "1",
Services: map[string]manifest.Service{
"one": {
Name: "one",
Labels: manifest.Labels{
"convox.cron.task1": "00 19 * * ? ls -la",
},
},
"two": {
Name: "two",
Labels: manifest.Labels{
"convox.cron.task2": "00 20 * * ? ls -la",
"convox.cron.task3": "00 21 * * ? ls -la",
},
},
},
}
a := models.App{
Name: "httpd",
Tags: map[string]string{
"Name": "httpd",
"Type": "app",
"System": "convox",
"Rack": "convox-test",
},
}
cj := a.CronJobs(m)
sort.Sort(models.CronJobs(cj))
assert.Equal(t, len(cj), 3)
assert.Equal(t, cj[0].Name, "task1")
assert.Equal(t, cj[0].Service.Name, "one")
assert.Equal(t, cj[1].Service.Name, "two")
assert.Equal(t, cj[1].Name, "task2")
assert.Equal(t, cj[2].Service.Name, "two")
assert.Equal(t, cj[2].Name, "task3")
}
func TestAppAgents(t *testing.T) {
m := manifest.Manifest{
Version: "1",
Services: map[string]manifest.Service{
"one": {
Name: "one",
Labels: manifest.Labels{
"convox.agent": "true",
},
},
},
}
a := models.App{
Name: "httpd",
Tags: map[string]string{
"Name": "httpd",
"Type": "app",
"System": "convox",
"Rack": "convox-test",
},
}
agents := a.Agents(m)
assert.Equal(t, len(agents), 1)
assert.Equal(t, agents[0].Service.Name, "one")
}