dewrich closed pull request #2721: Add TO Go JSONNumAsStr unmarshal unit test
URL: https://github.com/apache/trafficcontrol/pull/2721
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/lib/go-util/num_test.go b/lib/go-util/num_test.go
index 06e8aa296..a1fa12df4 100644
--- a/lib/go-util/num_test.go
+++ b/lib/go-util/num_test.go
@@ -17,6 +17,7 @@ package util
 // When adding symbols, document the RFC and section they correspond to.
 
 import (
+       "encoding/json"
        "reflect"
        "testing"
 )
@@ -178,3 +179,21 @@ func TestBytesLenSplit(t *testing.T) {
                }
        }
 }
+
+func TestJSONNumAsStrUnmarshalJSON(t *testing.T) {
+       type T struct {
+               V JSONNumAsStr `json:"v"`
+       }
+       jNum := `{"v":42}`
+       expected := T{V: "42"}
+       actual := T{}
+       json.Unmarshal([]byte(jNum), &actual)
+       if expected != actual {
+               t.Errorf("JSONNumAsStr number unmarshal expected %v actual %v", 
expected, actual)
+       }
+       jStr := `{"v":"42"}`
+       json.Unmarshal([]byte(jStr), &actual)
+       if expected != actual {
+               t.Errorf("JSONNumAsStr string unmarshal expected %v actual %v", 
expected, actual)
+       }
+}


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to