forked from emicklei/go-restful-swagger12
-
Notifications
You must be signed in to change notification settings - Fork 7
/
util_test.go
executable file
·77 lines (72 loc) · 1.92 KB
/
util_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
package swagger
import (
"testing"
)
type mathTest struct {
beforName, afterName string
}
func TestGetModelName(t *testing.T) {
modelName := []mathTest{
mathTest{"main.Book", "#/definitions/Book"},
mathTest{"swagger.Student", "#/definitions/Student"},
mathTest{"Teacher", "#/definitions/Teacher"},
}
for _, n := range modelName {
afterName := getModelName(n.beforName)
if afterName != n.afterName {
t.Errorf("get %v but not %v", afterName, n.afterName)
}
}
}
func TestGetOtherName(t *testing.T) {
otherName := []mathTest{
mathTest{"int", "integer"},
mathTest{"int8", "integer"},
mathTest{"int16", "integer"},
mathTest{"int32", "integer"},
mathTest{"int64", "integer"},
mathTest{"float32", "number"},
mathTest{"float64", "number"},
mathTest{"string", "string"},
mathTest{"bool", "boolean"},
mathTest{"uint", "integer"},
mathTest{"uint8", "integer"},
mathTest{"uint16", "integer"},
mathTest{"uint32", "integer"},
mathTest{"uint64", "integer"},
mathTest{"byte", "integer"},
mathTest{"time.Time", "string"},
mathTest{"file", "file"},
mathTest{"time", "time"},
mathTest{"date", "date"},
}
for _, o := range otherName {
afterName := getOtherName(o.beforName)
if afterName != o.afterName {
t.Errorf("get %v but not %v", afterName, o.afterName)
}
}
}
func TestGetFormat(t *testing.T) {
formatName := []mathTest{
mathTest{"int", "int32"},
mathTest{"int32", "int32"},
mathTest{"int64", "int64"},
mathTest{"float32", "float"},
mathTest{"float64", "double"},
mathTest{"byte", "byte"},
mathTest{"uint8", "byte"},
mathTest{"time.Time", "date-time"},
mathTest{"*time.Time", "date-time"},
mathTest{"datetime", "date-time"},
mathTest{"dateTime", "date-time"},
mathTest{"string", ""},
mathTest{"file", ""},
}
for _, f := range formatName {
afterName := getFormat(f.beforName)
if afterName != f.afterName {
t.Errorf("get %v but not %v", afterName, f.afterName)
}
}
}