Skip to content

Commit 660596a

Browse files
committed
added more UnmarshalOutput tests
1 parent b85b7e8 commit 660596a

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

utils_test.go

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,26 @@ func TestGenKey(t *testing.T) {
2424
}
2525
}
2626

27-
func TestUnmarshalOutput(t *testing.T) {
27+
func TestUnmarshalOutputNormal(t *testing.T) {
2828
expected := "1.0"
2929
testJSON := fmt.Sprintf(`{"APP_VERSION": "%s"}`, expected)
30-
result, err := unmarshalOutput(testJSON)
31-
if err != nil {
32-
t.Errorf("TestUnmarshalOutput failed: %v", err)
33-
}
30+
result, _ := unmarshalOutput(testJSON)
3431
if result.Version != expected {
3532
t.Errorf("expected %s; got %s\n", expected, result.Version)
3633
}
3734
}
35+
36+
func TestUnmarshalOutputUnmarshalFailure(t *testing.T) {
37+
if _, err := unmarshalOutput(`{test}`); err == nil {
38+
t.Error("JSON unmarshalling should fail")
39+
}
40+
}
41+
42+
func TestUnmarshalOutputNotJSONArray(t *testing.T) {
43+
defer func() {
44+
if r := recover(); r == nil {
45+
t.Error("expected: runtime error: slice bounds out of range")
46+
}
47+
}()
48+
unmarshalOutput(``)
49+
}

0 commit comments

Comments
 (0)