Skip to content

Commit

Permalink
types: add a couple more tests for the IP JSON unmarshaling
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick Jakubowski <[email protected]>
  • Loading branch information
patjakdev committed Nov 12, 2024
1 parent eea990b commit 60bdba3
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions types/json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func TestTypedJSONUnmarshal(t *testing.T) {
wantErr: nil,
},
{
name: "ip",
name: "ip/explicit",
f: func(b []byte) (Value, error) {
var res IPAddr
err := (&res).UnmarshalJSON(b)
Expand All @@ -128,7 +128,7 @@ func TestTypedJSONUnmarshal(t *testing.T) {
wantErr: nil,
},
{
name: "ip/implicit",
name: "ip/implicit/string",
f: func(b []byte) (Value, error) {
var res IPAddr
err := (&res).UnmarshalJSON(b)
Expand All @@ -138,6 +138,17 @@ func TestTypedJSONUnmarshal(t *testing.T) {
wantValue: mustIPValue("222.222.222.7"),
wantErr: nil,
},
{
name: "ip/implicit/JSON",
f: func(b []byte) (Value, error) {
var res IPAddr
err := (&res).UnmarshalJSON(b)
return res, err
},
in: `{ "fn": "ip", "arg": "222.222.222.7" }`,
wantValue: mustIPValue("222.222.222.7"),
wantErr: nil,
},
{
name: "ip/implicit/badJSON",
f: func(b []byte) (Value, error) {
Expand All @@ -149,6 +160,17 @@ func TestTypedJSONUnmarshal(t *testing.T) {
wantValue: IPAddr{},
wantErr: errJSONDecode,
},
{
name: "ip/implicit/notIP",
f: func(b []byte) (Value, error) {
var res IPAddr
err := (&res).UnmarshalJSON(b)
return res, err
},
in: `{"fn": "datetime"}`,
wantValue: IPAddr{},
wantErr: errJSONExtFnMatch,
},
{
name: "ip/badArg",
f: func(b []byte) (Value, error) {
Expand Down

0 comments on commit 60bdba3

Please sign in to comment.