forked from swaggo/swag
-
Notifications
You must be signed in to change notification settings - Fork 0
/
schema_test.go
58 lines (47 loc) · 1.99 KB
/
schema_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
package swag
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestValidDataType(t *testing.T) {
assert.NoError(t, CheckSchemaType(STRING))
assert.NoError(t, CheckSchemaType(NUMBER))
assert.NoError(t, CheckSchemaType(INTEGER))
assert.NoError(t, CheckSchemaType(BOOLEAN))
assert.NoError(t, CheckSchemaType(ARRAY))
assert.NoError(t, CheckSchemaType(OBJECT))
assert.Error(t, CheckSchemaType("oops"))
}
func TestTransToValidSchemeType(t *testing.T) {
assert.Equal(t, TransToValidSchemeType("uint"), INTEGER)
assert.Equal(t, TransToValidSchemeType("uint32"), INTEGER)
assert.Equal(t, TransToValidSchemeType("uint64"), INTEGER)
assert.Equal(t, TransToValidSchemeType("float32"), NUMBER)
assert.Equal(t, TransToValidSchemeType("bool"), BOOLEAN)
assert.Equal(t, TransToValidSchemeType("string"), STRING)
// should accept any type, due to user defined types
TransToValidSchemeType("oops")
}
func TestIsGolangPrimitiveType(t *testing.T) {
assert.Equal(t, IsGolangPrimitiveType("uint"), true)
assert.Equal(t, IsGolangPrimitiveType("int"), true)
assert.Equal(t, IsGolangPrimitiveType("uint8"), true)
assert.Equal(t, IsGolangPrimitiveType("uint16"), true)
assert.Equal(t, IsGolangPrimitiveType("int16"), true)
assert.Equal(t, IsGolangPrimitiveType("byte"), true)
assert.Equal(t, IsGolangPrimitiveType("uint32"), true)
assert.Equal(t, IsGolangPrimitiveType("int32"), true)
assert.Equal(t, IsGolangPrimitiveType("rune"), true)
assert.Equal(t, IsGolangPrimitiveType("uint64"), true)
assert.Equal(t, IsGolangPrimitiveType("int64"), true)
assert.Equal(t, IsGolangPrimitiveType("float32"), true)
assert.Equal(t, IsGolangPrimitiveType("float64"), true)
assert.Equal(t, IsGolangPrimitiveType("bool"), true)
assert.Equal(t, IsGolangPrimitiveType("string"), true)
assert.Equal(t, IsGolangPrimitiveType("oops"), false)
}
func TestIsNumericType(t *testing.T) {
assert.Equal(t, IsNumericType(INTEGER), true)
assert.Equal(t, IsNumericType(NUMBER), true)
assert.Equal(t, IsNumericType(STRING), false)
}