Skip to content

Commit 4aa36eb

Browse files
committed
fix(healthcheck): show all the healthchecks set when no proctype is specified
1 parent 0391c6c commit 4aa36eb

3 files changed

Lines changed: 147 additions & 8 deletions

File tree

cmd/healthchecks.go

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package cmd
22

33
import (
4+
"sort"
5+
46
"github.com/deis/controller-sdk-go/api"
57
"github.com/deis/controller-sdk-go/config"
68
)
@@ -34,12 +36,28 @@ func (d *DeisCmd) HealthchecksList(appID, procType string) error {
3436
return err
3537
}
3638

37-
d.Printf("=== %s Healthchecks\n\n", appID)
38-
d.Println(procType + ":")
39-
if healthcheck, found := config.Healthcheck[procType]; found {
40-
d.printHealthCheck(*healthcheck)
39+
d.Printf("=== %s Healthchecks\n", appID)
40+
if procType == "" {
41+
if len(config.Healthcheck) == 0 {
42+
d.Println("No health checks configured.")
43+
return nil
44+
}
45+
var keys []string
46+
for k := range config.Healthcheck {
47+
keys = append(keys, k)
48+
}
49+
sort.Strings(keys)
50+
for _, key := range keys {
51+
d.Printf("\n%s:\n", key)
52+
d.printHealthCheck(*config.Healthcheck[key])
53+
}
4154
} else {
42-
d.printHealthCheck(api.Healthchecks{})
55+
d.Printf("\n%s:\n", procType)
56+
if healthcheck, found := config.Healthcheck[procType]; found {
57+
d.printHealthCheck(*healthcheck)
58+
} else {
59+
d.printHealthCheck(api.Healthchecks{})
60+
}
4361
}
4462

4563
return nil

cmd/healthchecks_test.go

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,130 @@ No readiness probe configured.
9393
`, "output")
9494
}
9595

96+
func TestHealthchecksListNoHealthCheck(t *testing.T) {
97+
t.Parallel()
98+
cf, server, err := testutil.NewTestServerAndClient()
99+
if err != nil {
100+
t.Fatal(err)
101+
}
102+
defer server.Close()
103+
var b bytes.Buffer
104+
cmdr := DeisCmd{WOut: &b, ConfigFile: cf}
105+
106+
server.Mux.HandleFunc("/v2/apps/foo/config/", func(w http.ResponseWriter, r *http.Request) {
107+
testutil.SetHeaders(w)
108+
fmt.Fprintf(w, `{
109+
"uuid": "c039a380-6068-4511-b35a-535a73b86ef5",
110+
"app": "foo",
111+
"owner": "bar",
112+
"values": {},
113+
"memory": {},
114+
"cpu": {},
115+
"tags": {},
116+
"registry": {},
117+
"healthcheck": {},
118+
"created": "2016-09-12T22:20:14Z",
119+
"updated": "2016-09-12T22:20:14Z"
120+
}`)
121+
})
122+
123+
err = cmdr.HealthchecksList("foo", "")
124+
assert.NoErr(t, err)
125+
126+
assert.Equal(t, b.String(), `=== foo Healthchecks
127+
No health checks configured.
128+
`, "output")
129+
}
130+
131+
func TestHealthchecksListAllHealthChecks(t *testing.T) {
132+
t.Parallel()
133+
cf, server, err := testutil.NewTestServerAndClient()
134+
if err != nil {
135+
t.Fatal(err)
136+
}
137+
defer server.Close()
138+
var b bytes.Buffer
139+
cmdr := DeisCmd{WOut: &b, ConfigFile: cf}
140+
141+
server.Mux.HandleFunc("/v2/apps/foo/config/", func(w http.ResponseWriter, r *http.Request) {
142+
testutil.SetHeaders(w)
143+
fmt.Fprintf(w, `{
144+
"uuid": "c039a380-6068-4511-b35a-535a73b86ef5",
145+
"app": "foo",
146+
"owner": "bar",
147+
"values": {},
148+
"memory": {},
149+
"cpu": {},
150+
"tags": {},
151+
"registry": {},
152+
"healthcheck": {
153+
"web/cmd": {
154+
"livenessProbe": {
155+
"initialDelaySeconds": 50,
156+
"timeoutSeconds": 50,
157+
"periodSeconds": 10,
158+
"failureThreshold": 3,
159+
"httpGet": {
160+
"port": 80,
161+
"path": "/"
162+
},
163+
"successThreshold": 1
164+
}
165+
},
166+
"web": {
167+
"livenessProbe": {
168+
"initialDelaySeconds": 50,
169+
"timeoutSeconds": 50,
170+
"periodSeconds": 10,
171+
"failureThreshold": 3,
172+
"httpGet": {
173+
"port": 80,
174+
"path": "/"
175+
},
176+
"successThreshold": 1
177+
}
178+
}
179+
},
180+
"created": "2016-09-12T22:20:14Z",
181+
"updated": "2016-09-12T22:20:14Z"
182+
}`)
183+
})
184+
185+
err = cmdr.HealthchecksList("foo", "")
186+
assert.NoErr(t, err)
187+
188+
assert.Equal(t, b.String(), `=== foo Healthchecks
189+
190+
web:
191+
--- Liveness
192+
Initial Delay (seconds): 50
193+
Timeout (seconds): 50
194+
Period (seconds): 10
195+
Success Threshold: 1
196+
Failure Threshold: 3
197+
Exec Probe: N/A
198+
HTTP GET Probe: Path="/" Port=80 HTTPHeaders=[]
199+
TCP Socket Probe: N/A
200+
201+
--- Readiness
202+
No readiness probe configured.
203+
204+
web/cmd:
205+
--- Liveness
206+
Initial Delay (seconds): 50
207+
Timeout (seconds): 50
208+
Period (seconds): 10
209+
Success Threshold: 1
210+
Failure Threshold: 3
211+
Exec Probe: N/A
212+
HTTP GET Probe: Path="/" Port=80 HTTPHeaders=[]
213+
TCP Socket Probe: N/A
214+
215+
--- Readiness
216+
No readiness probe configured.
217+
`, "output")
218+
}
219+
96220
func TestHealthchecksSet(t *testing.T) {
97221
t.Parallel()
98222
cf, server, err := testutil.NewTestServerAndClient()

parser/healthchecks.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,6 @@ Options:
7272

7373
app := safeGetValue(args, "--app")
7474
procType := safeGetValue(args, "--type")
75-
if procType == "" {
76-
procType = defaultProcType
77-
}
7875

7976
return cmdr.HealthchecksList(app, procType)
8077
}

0 commit comments

Comments
 (0)