Skip to content

Commit f948c83

Browse files
committed
test(cmd): fix tests.
fix tests for timeouts command
1 parent 9e7e80f commit f948c83

4 files changed

Lines changed: 38 additions & 39 deletions

File tree

cmd/cmd.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ type Commander interface {
5858
LimitsList(string) error
5959
LimitsSet(string, []string, string) error
6060
LimitsUnset(string, []string, string) error
61+
TimeoutsList(string) error
62+
TimeoutsSet(string, []string) error
63+
TimeoutsUnset(string, []string) error
6164
MaintenanceInfo(string) error
6265
MaintenanceEnable(string) error
6366
MaintenanceDisable(string) error

cmd/timeouts.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"github.com/notmaxx/controller-sdk-go/config"
1111
)
1212

13-
// LimitsList lists an app's timeouts.
13+
// TimeoutsList lists an app's timeouts.
1414
func (d *DeisCmd) TimeoutsList(appID string) error {
1515
s, appID, err := load(d.ConfigFile, appID)
1616

@@ -23,7 +23,7 @@ func (d *DeisCmd) TimeoutsList(appID string) error {
2323
return err
2424
}
2525

26-
d.Printf("=== %s Timeouts (sec)\n\n", appID)
26+
d.Printf("=== %s Timeouts (sec)\n", appID)
2727

2828
if len(config.Timeout) == 0 {
2929
d.Println("default (30 sec) or controlled by env KUBERNETES_POD_TERMINATION_GRACE_PERIOD_SECONDS")
@@ -40,7 +40,7 @@ func (d *DeisCmd) TimeoutsList(appID string) error {
4040
return nil
4141
}
4242

43-
// LimitsSet sets an app's timeouts.
43+
// TimeoutsSet sets an app's timeouts.
4444
func (d *DeisCmd) TimeoutsSet(appID string, timeouts []string) error {
4545
s, appID, err := load(d.ConfigFile, appID)
4646

@@ -72,7 +72,7 @@ func (d *DeisCmd) TimeoutsSet(appID string, timeouts []string) error {
7272
return d.TimeoutsList(appID)
7373
}
7474

75-
// LimitsUnset removes an app's timeouts.
75+
// TimeoutsUnset removes an app's timeouts.
7676
func (d *DeisCmd) TimeoutsUnset(appID string, timeouts []string) error {
7777
s, appID, err := load(d.ConfigFile, appID)
7878

@@ -123,7 +123,7 @@ func parseTimeouts(timeouts []string) (map[string]interface{}, error) {
123123
}
124124

125125
func parseTimeout(timeout string) (string, string, error) {
126-
regex := regexp.MustCompile("^[0-9]*$")
126+
regex := regexp.MustCompile("^([a-z0-9]+(?:-[a-z0-9]+)*)=([0-9]+)$")
127127

128128
if !regex.MatchString(timeout) {
129129
return "", "", fmt.Errorf(`%s doesn't fit format type=#

cmd/timeouts_test.go

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Examples: web=30 worker=300`
3030
{"=1", "", "", true, "=1" + errorHint},
3131
{"web=", "", "", true, "web=" + errorHint},
3232
{"1=", "", "", true, "1=" + errorHint},
33-
{"web=ABCD", "", "", true, "web=G" + errorHint},
33+
{"web=ABCD", "", "", true, "web=ABCD" + errorHint},
3434
}
3535

3636
for _, check := range cases {
@@ -57,7 +57,7 @@ func TestTimeoutTags(t *testing.T) {
5757

5858
cases := []parseTimeoutsCase{
5959
{[]string{"web=10", "worker=20"}, map[string]interface{}{"web": "10", "worker": "20"}, false, ""},
60-
{[]string{"foo=", "web=1G"}, nil, true, `foo= doesn't fit format type=#
60+
{[]string{"foo=", "web=10"}, nil, true, `foo= doesn't fit format type=#
6161
Examples: web=30 worker=300`},
6262
}
6363

@@ -105,10 +105,9 @@ func TestTimeoutsList(t *testing.T) {
105105

106106
err = cmdr.TimeoutsList("enterprise")
107107
assert.NoErr(t, err)
108-
assert.Equal(t, b.String(), `=== enterprise Timeouts
109-
web 10
110-
worker 20
111-
108+
assert.Equal(t, b.String(), `=== enterprise Timeouts (sec)
109+
web 10
110+
worker 20
112111
`, "output")
113112

114113
server.Mux.HandleFunc("/v2/apps/franklin/config/", func(w http.ResponseWriter, r *http.Request) {
@@ -130,9 +129,8 @@ worker 20
130129

131130
err = cmdr.TimeoutsList("franklin")
132131
assert.NoErr(t, err)
133-
assert.Equal(t, b.String(), `=== franklin Timeouts
132+
assert.Equal(t, b.String(), `=== franklin Timeouts (sec)
134133
default (30 sec) or controlled by env KUBERNETES_POD_TERMINATION_GRACE_PERIOD_SECONDS
135-
136134
`, "output")
137135
}
138136

@@ -148,7 +146,7 @@ func TestTimeoutsSet(t *testing.T) {
148146
testutil.SetHeaders(w)
149147
if r.Method == "POST" {
150148
testutil.AssertBody(t, api.Config{
151-
CPU: map[string]interface{}{
149+
Timeout: map[string]interface{}{
152150
"web": "10",
153151
},
154152
}, r)
@@ -161,7 +159,7 @@ func TestTimeoutsSet(t *testing.T) {
161159
"memory": {},
162160
"cpu": {},
163161
"termination_grace_period": {
164-
"web": 10
162+
"web": "10"
165163
},
166164
"tags": {},
167165
"registry": {},
@@ -179,16 +177,16 @@ func TestTimeoutsSet(t *testing.T) {
179177

180178
assert.Equal(t, testutil.StripProgress(b.String()), `Applying timeouts... done
181179
182-
=== foo Timeouts
183-
180+
=== foo Timeouts (sec)
181+
web 10
184182
`, "output")
185183

186184
server.Mux.HandleFunc("/v2/apps/franklin/config/", func(w http.ResponseWriter, r *http.Request) {
187185
testutil.SetHeaders(w)
188186
if r.Method == "POST" {
189187
testutil.AssertBody(t, api.Config{
190-
Memory: map[string]interface{}{
191-
"web": 10,
188+
Timeout: map[string]interface{}{
189+
"web": "10",
192190
},
193191
}, r)
194192
}
@@ -200,8 +198,8 @@ func TestTimeoutsSet(t *testing.T) {
200198
"memory": {},
201199
"cpu": {},
202200
"termination_grace_period": {
203-
"web": 10
204-
}
201+
"web": "10"
202+
},
205203
"tags": {},
206204
"registry": {},
207205
"created": "2014-01-01T00:00:00UTC",
@@ -216,20 +214,19 @@ func TestTimeoutsSet(t *testing.T) {
216214

217215
assert.Equal(t, testutil.StripProgress(b.String()), `Applying timeouts... done
218216
219-
=== franklin Timeouts
217+
=== franklin Timeouts (sec)
220218
web 10
221-
222219
`, "output")
223220

224221
// with requests/timeout parameter
225222
server.Mux.HandleFunc("/v2/apps/jim/config/", func(w http.ResponseWriter, r *http.Request) {
226223
testutil.SetHeaders(w)
227224
if r.Method == "POST" {
228225
testutil.AssertBody(t, api.Config{
229-
Memory: map[string]interface{}{
230-
"web": 10,
231-
"worker": 100,
232-
"db": 300,
226+
Timeout: map[string]interface{}{
227+
"web": "10",
228+
"worker": "100",
229+
"db": "300",
233230
},
234231
}, r)
235232
}
@@ -238,12 +235,12 @@ web 10
238235
"owner": "foo",
239236
"app": "jim",
240237
"values": {},
241-
"memory": {}
238+
"memory": {},
242239
"cpu": {},
243240
"termination_grace_period": {
244-
"web": 10,
245-
"worker": 100,
246-
"db": 300
241+
"web": "10",
242+
"worker": "100",
243+
"db": "300"
247244
},
248245
"tags": {},
249246
"registry": {},
@@ -259,11 +256,10 @@ web 10
259256

260257
assert.Equal(t, testutil.StripProgress(b.String()), `Applying timeouts... done
261258
262-
=== jim Timeouts
259+
=== jim Timeouts (sec)
263260
db 300
264261
web 10
265262
worker 100
266-
267263
`, "output")
268264

269265
}
@@ -280,7 +276,7 @@ func TestTimeoutsUnset(t *testing.T) {
280276
testutil.SetHeaders(w)
281277
if r.Method == "POST" {
282278
testutil.AssertBody(t, api.Config{
283-
Memory: map[string]interface{}{
279+
Timeout: map[string]interface{}{
284280
"web": nil,
285281
},
286282
}, r)
@@ -311,15 +307,15 @@ func TestTimeoutsUnset(t *testing.T) {
311307

312308
assert.Equal(t, testutil.StripProgress(b.String()), `Applying timeouts... done
313309
314-
=== foo Timeouts
310+
=== foo Timeouts (sec)
315311
web 10
316312
`, "output")
317313

318314
server.Mux.HandleFunc("/v2/apps/franklin/config/", func(w http.ResponseWriter, r *http.Request) {
319315
testutil.SetHeaders(w)
320316
if r.Method == "POST" {
321317
testutil.AssertBody(t, api.Config{
322-
CPU: map[string]interface{}{
318+
Timeout: map[string]interface{}{
323319
"web": nil,
324320
},
325321
}, r)
@@ -348,7 +344,7 @@ web 10
348344

349345
assert.Equal(t, testutil.StripProgress(b.String()), `Applying timeouts... done
350346
351-
=== franklin Timeouts
347+
=== franklin Timeouts (sec)
352348
web 10
353349
`, "output")
354350
}

parser/timeouts_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ func (d FakeDeisCmd) TimeoutsList(string) error {
1616
return errors.New("timeouts:list")
1717
}
1818

19-
func (d FakeDeisCmd) TimeoutsSet(string, []string, string) error {
19+
func (d FakeDeisCmd) TimeoutsSet(string, []string) error {
2020
return errors.New("timeouts:set")
2121
}
2222

23-
func (d FakeDeisCmd) TimeoutsUnset(string, []string, string) error {
23+
func (d FakeDeisCmd) TimeoutsUnset(string, []string) error {
2424
return errors.New("timeouts:unset")
2525
}
2626

0 commit comments

Comments
 (0)