forked from viant/toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathencoder_test.go
More file actions
37 lines (30 loc) · 726 Bytes
/
encoder_test.go
File metadata and controls
37 lines (30 loc) · 726 Bytes
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
35
36
37
package toolbox_test
import (
"bytes"
"testing"
"github.com/stretchr/testify/assert"
"github.com/viant/toolbox"
)
func TestEncoderFactory(t *testing.T) {
buffer := new(bytes.Buffer)
assert.NotNil(t, toolbox.NewJSONEncoderFactory().Create(buffer))
}
func TestMarshalEncoderFactory(t *testing.T) {
buffer := new(bytes.Buffer)
encoder := toolbox.NewMarshalerEncoderFactory().Create(buffer)
foo := &Foo200{"abc"}
err := encoder.Encode(foo)
assert.Nil(t, err)
assert.Equal(t, "abc", string(buffer.Bytes()))
err = encoder.Encode(&Foo201{})
assert.NotNil(t, err)
}
type Foo200 struct {
Attr string
}
func (m *Foo200) Marshal() ([]byte, error) {
return []byte(m.Attr), nil
}
type Foo201 struct {
Attr string
}