-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstages_test.go
176 lines (146 loc) · 3.5 KB
/
stages_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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
package config
import (
"testing"
"github.com/tj/assert"
)
func TestStage_Override(t *testing.T) {
c, err := ParseConfigString(`{
"name": "app",
"regions": ["us-west-2"],
"lambda": {
"memory": 128
},
"hooks": {
"build": "parcel index.html -o build",
"clean": "rm -fr build"
},
"proxy": {
"command": "node app.js"
},
"stages": {
"production": {
"lambda": {
"memory": 1024
},
"hooks": {
"build": "parcel index.html -o build --production"
}
},
"staging": {
"proxy": {
"command": "node app.js --foo=bar"
}
}
}
}`)
assert.NoError(t, err, "parse")
assert.NoError(t, c.Default(), "default")
assert.NoError(t, c.Validate(), "validate")
assert.NoError(t, c.Override("production"), "override")
assert.Equal(t, 1024, c.Lambda.Memory)
assert.Equal(t, Hook{`parcel index.html -o build --production`}, c.Hooks.Build)
assert.Equal(t, `node app.js`, c.Proxy.Command)
assert.NoError(t, c.Override("staging"), "override")
assert.Equal(t, `node app.js --foo=bar`, c.Proxy.Command)
}
func TestStages_Default(t *testing.T) {
t.Run("no custom stages", func(t *testing.T) {
s := Stages{}
assert.NoError(t, s.Default(), "default")
assert.NoError(t, s.Validate(), "validate")
assert.Len(t, s, 3)
assert.Equal(t, "staging", s["staging"].Name)
assert.Equal(t, "production", s["production"].Name)
})
t.Run("custom stages", func(t *testing.T) {
s := Stages{
"beta": &Stage{},
}
assert.NoError(t, s.Default(), "default")
assert.NoError(t, s.Validate(), "validate")
assert.Len(t, s, 4)
assert.Equal(t, "beta", s["beta"].Name)
assert.Equal(t, true, s["beta"].Zone)
})
}
func TestStages_Validate(t *testing.T) {
t.Run("no stages", func(t *testing.T) {
s := Stages{}
assert.NoError(t, s.Validate(), "validate")
})
t.Run("some stages", func(t *testing.T) {
s := Stages{
"staging": &Stage{
Domain: "gh-polls-stage.com",
},
"production": &Stage{
Domain: "gh-polls.com",
},
}
assert.NoError(t, s.Default(), "default")
assert.NoError(t, s.Validate(), "validate")
assert.Equal(t, "staging", s["staging"].Name)
assert.Equal(t, "production", s["production"].Name)
})
t.Run("valid zone boolean", func(t *testing.T) {
s := Stages{
"production": &Stage{
Domain: "gh-polls.com",
Zone: false,
},
}
assert.NoError(t, s.Default(), "default")
assert.NoError(t, s.Validate(), "validate")
})
t.Run("valid zone string", func(t *testing.T) {
s := Stages{
"production": &Stage{
Domain: "api.gh-polls.com",
Zone: "api.gh-polls.com",
},
}
assert.NoError(t, s.Default(), "default")
assert.NoError(t, s.Validate(), "validate")
})
t.Run("invalid zone type", func(t *testing.T) {
s := Stages{
"production": &Stage{
Domain: "api.gh-polls.com",
Zone: 123,
},
}
assert.NoError(t, s.Default(), "default")
assert.EqualError(t, s.Validate(), `stage "production": .zone is an invalid type, must be string or boolean`)
})
}
func TestStages_List(t *testing.T) {
stage := &Stage{
Domain: "gh-polls-stage.com",
}
prod := &Stage{
Domain: "gh-polls.com",
}
s := Stages{
"staging": stage,
"production": prod,
}
list := []*Stage{
stage,
prod,
}
stages := s.List()
assert.Equal(t, list, stages)
}
func TestStages_GetByDomain(t *testing.T) {
stage := &Stage{
Domain: "gh-polls-stage.com",
}
prod := &Stage{
Domain: "gh-polls.com",
}
s := Stages{
"staging": stage,
"production": prod,
}
assert.Equal(t, prod, s.GetByDomain("gh-polls.com"))
}