Skip to content

Commit 774e464

Browse files
committed
test: safer type assertions
Signed-off-by: Matej Vašek <matejvasek@gmail.com>
1 parent c1b9a38 commit 774e464

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

test/common/knative.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,21 @@ func GetCurrentServiceRevision(t *testing.T, serviceName string) string {
4848
}
4949

5050
func GetKnativeServiceRevisionAndUrl(t *testing.T, serviceName string) (revision string, url string) {
51+
t.Helper()
52+
var ok bool
5153
resource := RetrieveKnativeServiceResource(t, serviceName)
5254
rootMap := resource.UnstructuredContent()
53-
statusMap := rootMap["status"].(map[string]interface{})
54-
revision = statusMap["latestReadyRevisionName"].(string)
55-
url = statusMap["url"].(string)
55+
statusMap, ok := rootMap["status"].(map[string]interface{})
56+
if !ok {
57+
t.Fatal("absent status")
58+
}
59+
revision, ok = statusMap["latestReadyRevisionName"].(string)
60+
if !ok {
61+
t.Fatal("absent ready revision")
62+
}
63+
url, ok = statusMap["url"].(string)
64+
if !ok {
65+
t.Fatal("absent url")
66+
}
5667
return revision, url
5768
}

0 commit comments

Comments
 (0)