aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/aws/smithy-go/encoding/json/encoder_test.go
blob: d9fbd4ba82f05c8b038e38a2b3ba1bb3b2e331ea (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package json_test

import (
	"bytes"
	"testing"

	"github.com/aws/smithy-go/encoding/json"
)

func TestEncoder(t *testing.T) {
	encoder := json.NewEncoder()

	object := encoder.Object()

	object.Key("stringKey").String("stringValue")
	object.Key("integerKey").Long(1024)
	object.Key("floatKey").Double(3.14)

	subObj := object.Key("foo").Object()

	subObj.Key("byteSlice").Base64EncodeBytes([]byte("foo bar"))
	subObj.Close()

	object.Close()

	e := []byte(`{"stringKey":"stringValue","integerKey":1024,"floatKey":3.14,"foo":{"byteSlice":"Zm9vIGJhcg=="}}`)
	if a := encoder.Bytes(); bytes.Compare(e, a) != 0 {
		t.Errorf("expected %+q, but got %+q", e, a)
	}

	if a := encoder.String(); string(e) != a {
		t.Errorf("expected %s, but got %s", e, a)
	}
}