Skip to content

Commit b62303b

Browse files
author
James Waters
committed
Add deepobject tests for more complex types
Specifically, types that there are special edge-cases for
1 parent 1f1f116 commit b62303b

1 file changed

Lines changed: 23 additions & 5 deletions

File tree

deepobject_test.go

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"testing"
77
"time"
88

9+
"github.com/oapi-codegen/runtime/types"
910
"github.com/stretchr/testify/assert"
1011
"github.com/stretchr/testify/require"
1112
)
@@ -17,6 +18,7 @@ type InnerObject struct {
1718

1819
// These are all possible field types, mandatory and optional.
1920
type AllFields struct {
21+
// Primitive types
2022
I int `json:"i"`
2123
Oi *int `json:"oi,omitempty"`
2224
F float32 `json:"f"`
@@ -27,10 +29,16 @@ type AllFields struct {
2729
Oas *[]string `json:"oas,omitempty"`
2830
O InnerObject `json:"o"`
2931
Oo *InnerObject `json:"oo,omitempty"`
30-
D MockBinder `json:"d"`
31-
Od *MockBinder `json:"od,omitempty"`
3232
M map[string]int `json:"m"`
3333
Om *map[string]int `json:"om,omitempty"`
34+
35+
// Complex types
36+
Bi MockBinder `json:"bi"`
37+
Obi *MockBinder `json:"obi,omitempty"`
38+
Da types.Date `json:"da"`
39+
Oda *types.Date `json:"oda,omitempty"`
40+
Ti time.Time `json:"ti"`
41+
Oti *time.Time `json:"oti,omitempty"`
3442
}
3543

3644
func TestDeepObject(t *testing.T) {
@@ -45,9 +53,13 @@ func TestDeepObject(t *testing.T) {
4553
om := map[string]int{
4654
"additional": 1,
4755
}
48-
d := MockBinder{Time: time.Date(2020, 2, 1, 0, 0, 0, 0, time.UTC)}
56+
57+
bi := MockBinder{Time: time.Date(2020, 2, 1, 0, 0, 0, 0, time.UTC)}
58+
da := types.Date{Time: time.Date(2020, 2, 2, 0, 0, 0, 0, time.UTC)}
59+
ti := time.Now().UTC()
4960

5061
srcObj := AllFields{
62+
// Primitive types
5163
I: 12,
5264
Oi: &oi,
5365
F: 4.2,
@@ -61,10 +73,16 @@ func TestDeepObject(t *testing.T) {
6173
ID: 456,
6274
},
6375
Oo: &oo,
64-
D: d,
65-
Od: &d,
6676
M: om,
6777
Om: &om,
78+
79+
// Complex types
80+
Bi: bi,
81+
Obi: &bi,
82+
Da: da,
83+
Oda: &da,
84+
Ti: ti,
85+
Oti: &ti,
6886
}
6987

7088
marshaled, err := MarshalDeepObject(srcObj, "p")

0 commit comments

Comments
 (0)