Skip to content

Commit 1b72ab2

Browse files
authored
test: check daemon unmarshal errors (#1296)
## What? - Check JSON unmarshal errors in daemon handler tests. - Fail clearly when a response body cannot be decoded instead of ignoring the error. - Keep the change limited to daemon tests. ## Why? Ignoring `json.Unmarshal` errors can let malformed test responses pass into later assertions with less useful failures. This makes the daemon tests report decode problems at the source. Fixes #718
1 parent 4876a93 commit 1b72ab2

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

daemon/daemon_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ func TestDaemon_PingHandler(t *testing.T) {
9999
t.Fatal("expected Response")
100100
}
101101
var result daemonrpc.PingResult
102-
json.Unmarshal(msg.Response.Result, &result)
102+
if err := json.Unmarshal(msg.Response.Result, &result); err != nil {
103+
t.Fatalf("failed to unmarshal ping result: %v", err)
104+
}
103105
if !result.Pong {
104106
t.Error("expected pong=true")
105107
}
@@ -115,7 +117,9 @@ func TestDaemon_StatusHandler(t *testing.T) {
115117
msg := handlerTest(t, d, &daemonrpc.Request{ID: 1, Method: daemonrpc.MethodGetStatus})
116118

117119
var result daemonrpc.StatusResult
118-
json.Unmarshal(msg.Response.Result, &result)
120+
if err := json.Unmarshal(msg.Response.Result, &result); err != nil {
121+
t.Fatalf("failed to unmarshal status result: %v", err)
122+
}
119123

120124
if !result.Running {
121125
t.Error("expected running=true")

0 commit comments

Comments
 (0)