Skip to content

Commit

Permalink
add test that passed before v0.21.2 for omitempty tags
Browse files Browse the repository at this point in the history
Signed-off-by: Golang Lemonade <147884153+golanglemonade@users.noreply.github.com>
  • Loading branch information
golanglemonade committed Apr 23, 2024
1 parent 8309b96 commit 1df1b0b
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions clientv2/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,13 @@ func TestMarshalJSON(t *testing.T) {
Name string `json:"name"`
Number Number `json:"number"`
}

// example with omitted fields
type Input struct {
ID string `json:"id"`
Tags []string `json:"tags,omitempty"`
}

testDate := time.Date(2021, 1, 1, 0, 0, 0, 0, time.UTC)
type args struct {
v any
Expand Down Expand Up @@ -642,6 +649,37 @@ func TestMarshalJSON(t *testing.T) {
},
want: []byte(`{"time":"2021-01-01T00:00:00Z"}`),
},
{
name: "marshal omitted fields",
args: args{
v: Request{
OperationName: "query",
Query: `query ($input: Number!) { input }`,
Variables: map[string]any{
"input": Input{
ID: "1",
},
},
},
},
want: []byte(`{"operationName":"query", "query":"query ($input: Number!) { input }","variables":{"input":{"id":"1"}}}`),
},
{
name: "marshal fields",
args: args{
v: Request{
OperationName: "query",
Query: `query ($input: Number!) { input }`,
Variables: map[string]any{
"input": Input{
ID: "1",
Tags: []string{"tag1", "tag2"},
},
},
},
},
want: []byte(`{"operationName":"query", "query":"query ($input: Number!) { input }","variables":{"input":{"id":"1", "tags":["tag1","tag2"]}}}`),
},
{
name: "marshal time.Time",
args: args{
Expand Down

0 comments on commit 1df1b0b

Please # to comment.