-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathproperty_ext_test.go
110 lines (108 loc) · 3.66 KB
/
property_ext_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
109
110
package restfulspec
import (
"fmt"
"net"
"strings"
"testing"
)
// nolint:paralleltest
func TestThatExtraTagsAreReadIntoModel(t *testing.T) {
type fakeint int
type fakearray string
type Anything struct {
Name string `description:"name" modelDescription:"a test" readOnly:"false"`
Size int `minimum:"0" maximum:"10"`
Stati string `enum:"off|on" default:"on" modelDescription:"more description"`
ID string `unique:"true"`
FakeInt fakeint `type:"integer"`
FakeArray fakearray `type:"[]string"`
IP net.IP `type:"string"`
Password string
Optional bool `optional:"true"`
Created string `readOnly:"true"`
NullableField string `x-nullable:"true"`
NotNullableField string `x-nullable:"false"`
UUID string `type:"string" format:"UUID"`
XGoName string `x-go-name:"specgoname"`
ByteArray []byte `format:"binary"`
}
d := definitionsFromStruct(Anything{})
props, _ := d["restfulspec.Anything"]
p1, _ := props.Properties["Name"]
if got, want := p1.Description, "name"; got != want {
t.Errorf("got %v want %v", got, want)
}
if got, want := p1.ReadOnly, false; got != want {
t.Errorf("got %v want %v", got, want)
}
p2, _ := props.Properties["Size"]
if got, want := *p2.Minimum, 0.0; got != want {
t.Errorf("got %v want %v", got, want)
}
if got, want := p2.ReadOnly, false; got != want {
t.Errorf("got %v want %v", got, want)
}
if got, want := *p2.Maximum, 10.0; got != want {
t.Errorf("got %v want %v", got, want)
}
p3, _ := props.Properties["Stati"]
if got, want := p3.Enum[0], "off"; got != want {
t.Errorf("got %v want %v", got, want)
}
if got, want := p3.Enum[1], "on"; got != want {
t.Errorf("got %v want %v", got, want)
}
p4, _ := props.Properties["ID"]
if got, want := p4.UniqueItems, true; got != want {
t.Errorf("got %v want %v", got, want)
}
p5, _ := props.Properties["Password"]
if got, want := p5.Type[0], "string"; got != want {
t.Errorf("got %v want %v", got, want)
}
p6, _ := props.Properties["FakeInt"]
if got, want := p6.Type[0], "integer"; got != want {
t.Errorf("got %v want %v", got, want)
}
p7, _ := props.Properties["FakeArray"]
if got, want := p7.Type[0], "array"; got != want {
t.Errorf("got %v want %v", got, want)
}
p7p, _ := props.Properties["FakeArray"]
if got, want := p7p.Items.Schema.Type[0], "string"; got != want {
t.Errorf("got %v want %v", got, want)
}
p8, _ := props.Properties["IP"]
if got, want := p8.Type[0], "string"; got != want {
t.Errorf("got %v want %v", got, want)
}
p9, _ := props.Properties["Created"]
if got, want := p9.ReadOnly, true; got != want {
t.Errorf("got %v want %v", got, want)
}
if got, want := strings.Contains(fmt.Sprintf("%v", props.Required), "Optional"), false; got != want {
t.Errorf("got %v want %v", got, want)
}
if got, want := props.Description, "a test\nmore description"; got != want {
t.Errorf("got %v want %v", got, want)
}
p10, _ := props.Properties["NullableField"]
if got, want := p10.Extensions["x-nullable"], true; got != want {
t.Errorf("got %v want %v", got, want)
}
p11, _ := props.Properties["NotNullableField"]
if got, want := p11.Extensions["x-nullable"], false; got != want {
t.Errorf("got %v want %v", got, want)
}
p12, _ := props.Properties["UUID"]
if got, want := p12.Type[0], "string"; got != want {
t.Errorf("got %v want %v", got, want)
}
if got, want := p12.Format, "UUID"; got != want {
t.Errorf("got %v want %v", got, want)
}
p13, _ := props.Properties["XGoName"]
if got, want := p13.Extensions["x-go-name"], "specgoname"; got != want {
t.Errorf("got %v want %v", got, want)
}
}