-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel_test.go
More file actions
46 lines (37 loc) · 996 Bytes
/
Copy pathmodel_test.go
File metadata and controls
46 lines (37 loc) · 996 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
38
39
40
41
42
43
44
45
46
package main
import (
"encoding/json"
"testing"
"github.com/nchern/go-codegen/tests/immutable/model"
"github.com/stretchr/testify/assert"
)
func TestGeneratedImplementation(t *testing.T) {
m := model.NewDTOBuilder().
Foo("foo").
Bar(101).
Buzz(true).
Value(3.14).
Build()
assert.Equal(t, "foo", m.Foo())
assert.Equal(t, 101, m.Bar())
assert.True(t, m.Buzz())
assert.Equal(t, 3.14, m.Value())
}
func TestJSONEncodeDecode(t *testing.T) {
expected := model.NewDTOBuilder().
Foo("foo").
Bar(101).
Buzz(true).
Value(3.14).
Build()
encoded, err := json.Marshal(expected)
assert.NoError(t, err)
assert.True(t, len(encoded) > 0)
// assert.Equal(t, "{d}", string(encoded))
actual := model.NewDTOBuilder().Build()
assert.NoError(t, json.Unmarshal(encoded, actual))
assert.Equal(t, expected.Foo(), actual.Foo())
assert.Equal(t, expected.Bar(), actual.Bar())
assert.Equal(t, expected.Buzz(), actual.Buzz())
assert.Equal(t, expected.Value(), actual.Value())
}