Skip to content

Commit 87c5995

Browse files
Waterdripsalexellis
authored andcommitted
Fix type conversion in gateway version on nil
Signed-off-by: Alistair Hey <[email protected]>
1 parent e53b9c4 commit 87c5995

File tree

2 files changed

+52
-7
lines changed

2 files changed

+52
-7
lines changed

commands/version.go

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,18 @@ func printLogo() {
152152
func getGatewayDetails(m map[string]interface{}) (version, sha, commit string) {
153153
if _, ok := m["orchestration"]; !ok {
154154
v := m["version"].(map[string]interface{})
155-
version = v["release"].(string)
156-
sha = v["sha"].(string)
157-
commit = v["commit_message"].(string)
155+
version, ok = v["release"].(string)
156+
if !ok {
157+
version = ""
158+
}
159+
sha, ok = v["sha"].(string)
160+
if !ok {
161+
sha = ""
162+
}
163+
commit, ok = v["commit_message"].(string)
164+
if !ok {
165+
commit = ""
166+
}
158167
}
159168

160169
return
@@ -184,10 +193,22 @@ func getProviderDetailsLegacy(m map[string]interface{}) (name, orchestration, sh
184193

185194
func getProviderDetailsCurrent(m map[string]interface{}) (name, orchestration, sha, version string) {
186195
v := m["version"].(map[string]interface{})
187-
version = v["release"].(string)
188-
sha = v["sha"].(string)
189-
name = m["provider"].(string)
190-
orchestration = m["orchestration"].(string)
196+
version, ok := v["release"].(string)
197+
if !ok {
198+
version = ""
199+
}
200+
sha, ok = v["sha"].(string)
201+
if !ok {
202+
sha = ""
203+
}
204+
name, ok = m["provider"].(string)
205+
if !ok {
206+
name = ""
207+
}
208+
orchestration, ok = m["orchestration"].(string)
209+
if !ok {
210+
orchestration = ""
211+
}
191212

192213
return
193214
}

commands/version_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,21 @@ func Test_gateway_and_provider_information(t *testing.T) {
9999
{"provider sha", "sha: c890cba302d059de8edbef3f3de7fe15444b1ecf"},
100100
},
101101
},
102+
{
103+
responseBody: gateway_response_0_8_4_onwards_nil_values,
104+
params: []struct {
105+
name string
106+
value string
107+
}{
108+
{"gateway version", "version: "},
109+
{"gateway sha", "sha: "},
110+
{"gateway commit", "commit: "},
111+
{"provider name", "name: "},
112+
{"provider orchestration", "orchestration: "},
113+
{"provider version", "version: "},
114+
{"provider sha", "sha: "},
115+
},
116+
},
102117
{
103118
responseBody: gateway_response_prior_to_0_8_4,
104119
params: []struct {
@@ -199,6 +214,15 @@ const gateway_response_0_8_4_onwards = `{
199214
}
200215
}`
201216

217+
const gateway_response_0_8_4_onwards_nil_values = `{
218+
"provider": {
219+
"version": {
220+
}
221+
},
222+
"version": {
223+
}
224+
}`
225+
202226
const gateway_response_prior_to_0_8_4 = `{
203227
"provider": "faas-swarm",
204228
"version": {

0 commit comments

Comments
 (0)