From 1df1b0bd19ba2e767dcb82279babc28593ca604d Mon Sep 17 00:00:00 2001 From: Golang Lemonade <147884153+golanglemonade@users.noreply.github.com> Date: Tue, 23 Apr 2024 16:57:58 -0600 Subject: [PATCH] add test that passed before v0.21.2 for omitempty tags Signed-off-by: Golang Lemonade <147884153+golanglemonade@users.noreply.github.com> --- clientv2/client_test.go | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/clientv2/client_test.go b/clientv2/client_test.go index da9606b..ef58324 100644 --- a/clientv2/client_test.go +++ b/clientv2/client_test.go @@ -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 @@ -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{