From 6c2fbcbaa79db4ddd1cddfb43a23649d9ed76197 Mon Sep 17 00:00:00 2001 From: Martin Rode Date: Sun, 10 Nov 2024 10:22:16 +0100 Subject: [PATCH] test: fix unit tests --- pkg/lib/api/response_test.go | 2 +- pkg/lib/util/json_test.go | 21 ++++++++++----------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/pkg/lib/api/response_test.go b/pkg/lib/api/response_test.go index e1b1e22..09ed96a 100644 --- a/pkg/lib/api/response_test.go +++ b/pkg/lib/api/response_test.go @@ -30,7 +30,7 @@ func TestResponse_ToGenericJson(t *testing.T) { if !ok { t.Fatalf("responseJsonObj should have status code field") } - if statusCode != json.Number("200") { + if statusCode != float64(200) { t.Errorf("responseJson had wrong statuscode, expected 200, got: %d", statusCode) } jsonHeaders, ok := jsonObjResp["header"] diff --git a/pkg/lib/util/json_test.go b/pkg/lib/util/json_test.go index 1588b59..8f7f25b 100644 --- a/pkg/lib/util/json_test.go +++ b/pkg/lib/util/json_test.go @@ -1,7 +1,6 @@ package util import ( - "encoding/json" "fmt" "testing" @@ -97,7 +96,7 @@ welt:1 for _, v := range testCases { var out JsonObject - oErr := UnmarshalWithNumber([]byte(v.iJson), &out) + oErr := Unmarshal([]byte(v.iJson), &out) go_test_utils.AssertErrorEquals(t, oErr, v.eError) } @@ -114,7 +113,7 @@ func TestRemoveComments(t *testing.T) { "hallo":2 }`, JsonObject{ - "hallo": json.Number("2"), + "hallo": float64(2), }, }, { @@ -122,7 +121,7 @@ func TestRemoveComments(t *testing.T) { "hallo":2 }`, JsonObject{ - "hallo": json.Number("2"), + "hallo": float64(2), }, }, { @@ -133,7 +132,7 @@ func TestRemoveComments(t *testing.T) { #line2 }`, JsonObject{ - "hallo": json.Number("2"), + "hallo": float64(2), }, }, { @@ -145,7 +144,7 @@ func TestRemoveComments(t *testing.T) { "hey":"ha" }`, JsonObject{ - "hallo": json.Number("2"), + "hallo": float64(2), "hey": "ha", }, }, @@ -153,10 +152,10 @@ func TestRemoveComments(t *testing.T) { for _, v := range testCases { var out JsonObject - UnmarshalWithNumber([]byte(v.iJson), &out) + Unmarshal([]byte(v.iJson), &out) for k, v := range v.eOut { if out[k] != v { - t.Errorf("[%s] Have '%v' != '%f' want", k, out[k], v) + t.Errorf("[%s] Have %T '%v' != '%f' want", k, k, out[k], v) } } } @@ -172,7 +171,7 @@ func TestCJSONUnmarshalSyntaxErr(t *testing.T) { { `{"hallo":3}`, JsonObject{ - "hallo": json.Number("3"), + "hallo": float64(3), }, nil, }, @@ -245,7 +244,7 @@ func TestCJSONUnmarshalSyntaxErr(t *testing.T) { for _, v := range testCases { oObject := JsonObject{} - oErr := UnmarshalWithNumber([]byte(v.cjsonString), &oObject) + oErr := Unmarshal([]byte(v.cjsonString), &oObject) go_test_utils.AssertErrorEquals(t, oErr, v.eError) if oErr == nil { @@ -270,7 +269,7 @@ func TestCJSONUnmarshalTypeErr(t *testing.T) { var oObject expectedStructure - oErr := UnmarshalWithNumber( + oErr := Unmarshal( []byte(cjsonString), &oObject, )