From 5370934c0aeea6aafbd0942f735d9fc1b5a1c8e0 Mon Sep 17 00:00:00 2001 From: Gareth Kirwan Date: Fri, 16 Aug 2024 10:50:25 +0700 Subject: [PATCH] fixup! Kraken: Handle Errors field in futures response --- exchanges/kraken/kraken_test.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/exchanges/kraken/kraken_test.go b/exchanges/kraken/kraken_test.go index cf3b9154d91..0db256b2427 100644 --- a/exchanges/kraken/kraken_test.go +++ b/exchanges/kraken/kraken_test.go @@ -2394,3 +2394,20 @@ func TestErrorResponse(t *testing.T) { }) } } + +func TestGetFuturesErr(t *testing.T) { + t.Parallel() + + assert.ErrorContains(t, getFuturesErr(json.RawMessage(`unparsable rubbish`)), "invalid character", "Bad JSON should error correctly") + assert.NoError(t, getFuturesErr(json.RawMessage(`{"candles":[]}`)), "JSON with no Result should not error") + assert.NoError(t, getFuturesErr(json.RawMessage(`{"Result":"4 goats"}`)), "JSON with non-error Result should not error") + assert.ErrorIs(t, getFuturesErr(json.RawMessage(`{"Result":"error"}`)), common.ErrUnknownError, "JSON with error Result should error correctly") + assert.ErrorContains(t, getFuturesErr(json.RawMessage(`{"Result":"error", "error": "1 goat"}`)), "1 goat", "JSON with an error should error correctly") + err := getFuturesErr(json.RawMessage(`{"Result":"error", "errors": ["2 goats", "3 goats"]}`)) + assert.ErrorContains(t, err, "2 goat", "JSON with errors should error correctly") + assert.ErrorContains(t, err, "3 goat", "JSON with errors should error correctly") + err = getFuturesErr(json.RawMessage(`{"Result":"error", "error": "too many goats", "errors": ["2 goats", "3 goats"]}`)) + assert.ErrorContains(t, err, "2 goat", "JSON with both error and errors should error correctly") + assert.ErrorContains(t, err, "3 goat", "JSON with both error and errors should error correctly") + assert.ErrorContains(t, err, "too many goat", "JSON both error and with errors should error correctly") +}