forked from a-h/generate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadditionalProperties2_test.go
108 lines (93 loc) · 2.53 KB
/
additionalProperties2_test.go
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package test
import (
"encoding/json"
"log"
"reflect"
"testing"
"github.com/a-h/generate/test/additionalProperties2_gen"
)
func TestMarshalUnmarshal(t *testing.T) {
params := []struct {
Name string
Strct additionalProperties2.AdditionalProperties
Validation func(t *testing.T, prop *additionalProperties2.AdditionalProperties)
}{
{
Name: "Base Object",
Strct: additionalProperties2.AdditionalProperties{
Property1: "test",
},
Validation: func(t *testing.T, prop *additionalProperties2.AdditionalProperties) {
if prop.Property1 != "test" {
t.Fatal("property1 != test")
}
},
},
{
Name: "Property7",
Strct: additionalProperties2.AdditionalProperties{
Property7: &additionalProperties2.Property7{
StreetNumber: 69,
StreetName: "Elm St",
PoBox: &additionalProperties2.PoBox{
Suburb: "Smallville",
},
AdditionalProperties: map[string]map[string]*additionalProperties2.Anonymous1{
"red": {
"blue": {
Color: "green",
Conditions: []*additionalProperties2.ConditionsItems{
{Name: "dry"},
},
Density: 42.42,
},
},
"orange": {},
},
},
},
Validation: func(t *testing.T, prop *additionalProperties2.AdditionalProperties) {
if prop.Property7.StreetNumber != 69 {
t.Fatal("wrong value")
}
if len(prop.Property7.AdditionalProperties) != 2 {
t.Fatal("not enough additionalProperties")
}
if prop.Property7.AdditionalProperties["red"]["blue"].Color != "green" {
t.Fatal("wrong nested value")
}
if prop.Property7.AdditionalProperties["red"]["blue"].Density != 42.42 {
t.Fatal("wrong nested value")
}
},
},
}
for _, p := range params {
if str, err := json.MarshalIndent(&p.Strct, "", " "); err != nil {
t.Fatal(err)
} else {
//log.Println(string(str))
strct2 := &additionalProperties2.AdditionalProperties{}
if err := json.Unmarshal(str, &strct2); err != nil {
t.Fatal(err)
}
if reflect.DeepEqual(p.Strct, strct2) {
log.Fatal("unmarshaled struct != given struct")
}
p.Validation(t, strct2)
if str, err := json.MarshalIndent(&strct2, "", " "); err != nil {
t.Fatal(err)
} else {
//log.Println(string(str))
strct3 := &additionalProperties2.AdditionalProperties{}
if err := json.Unmarshal(str, &strct3); err != nil {
t.Fatal(err)
}
if reflect.DeepEqual(p.Strct, strct3) {
log.Fatal("unmarshaled struct != given struct")
}
p.Validation(t, strct3)
}
}
}
}