diff options
author | vitalyisaev <vitalyisaev@ydb.tech> | 2023-12-12 21:55:07 +0300 |
---|---|---|
committer | vitalyisaev <vitalyisaev@ydb.tech> | 2023-12-12 22:25:10 +0300 |
commit | 4967f99474a4040ba150eb04995de06342252718 (patch) | |
tree | c9c118836513a8fab6e9fcfb25be5d404338bca7 /vendor/github.com/aws/smithy-go/encoding/json/decoder_util_test.go | |
parent | 2ce9cccb9b0bdd4cd7a3491dc5cbf8687cda51de (diff) | |
download | ydb-4967f99474a4040ba150eb04995de06342252718.tar.gz |
YQ Connector: prepare code base for S3 integration
1. Кодовая база Коннектора переписана с помощью Go дженериков так, чтобы добавление нового источника данных (в частности S3 + csv) максимально переиспользовало имеющийся код (чтобы сохранялась логика нарезания на блоки данных, учёт трафика и пр.)
2. API Connector расширено для работы с S3, но ещё пока не протестировано.
Diffstat (limited to 'vendor/github.com/aws/smithy-go/encoding/json/decoder_util_test.go')
-rw-r--r-- | vendor/github.com/aws/smithy-go/encoding/json/decoder_util_test.go | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/vendor/github.com/aws/smithy-go/encoding/json/decoder_util_test.go b/vendor/github.com/aws/smithy-go/encoding/json/decoder_util_test.go new file mode 100644 index 0000000000..e4cb38e8b7 --- /dev/null +++ b/vendor/github.com/aws/smithy-go/encoding/json/decoder_util_test.go @@ -0,0 +1,65 @@ +package json + +import ( + "bytes" + "encoding/json" + "testing" + + smithytesting "github.com/aws/smithy-go/testing" +) + +func TestDiscardUnknownField(t *testing.T) { + cases := map[string][]byte{ + "empty object": []byte(`{}`), + "simple object": []byte(`{"foo": "bar"}`), + "nested object": []byte(`{"foo": {"bar": "baz"}}`), + "empty list": []byte(`[]`), + "simple list": []byte(`["foo", "bar", "baz"]`), + "nested list": []byte(`["foo", ["bar", ["baz"]]]`), + "number": []byte(`1`), + "boolean": []byte(`true`), + "null": []byte(`null`), + "string": []byte(`"foo"`), + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + buff := bytes.NewBuffer(c) + decoder := json.NewDecoder(buff) + err := DiscardUnknownField(decoder) + if err != nil { + t.Fatalf("failed to discard, %v", err) + } + if decoder.More() { + t.Fatalf("failed to discard entire contents") + } + }) + } +} + +func TestCollectUnknownField(t *testing.T) { + cases := map[string][]byte{ + "empty object": []byte(`{}`), + "simple object": []byte(`{"foo": "bar"}`), + "nested object": []byte(`{"foo": {"bar": "baz"}}`), + "empty list": []byte(`[]`), + "simple list": []byte(`["foo", "bar", "baz"]`), + "nested list": []byte(`["foo", ["bar", ["baz"]]]`), + "number": []byte(`1`), + "boolean": []byte(`true`), + "null": []byte(`null`), + "string": []byte(`"foo"`), + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + buff := bytes.NewBuffer(c) + decoder := json.NewDecoder(buff) + actual, err := CollectUnknownField(decoder) + if err != nil { + t.Fatalf("failed to collect, %v", err) + } + smithytesting.AssertJSONEqual(t, c, actual) + }) + } +} |