-
Notifications
You must be signed in to change notification settings - Fork 4
/
server_spec_test.go
53 lines (41 loc) · 1.34 KB
/
server_spec_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
package porthos
import (
"testing"
)
func TestBodySpecSimple(t *testing.T) {
type X struct {
Value int `json:"value"`
}
bodySpec := BodySpecFromStruct(X{})
if bodySpec["value"].Type != "int" {
t.Errorf("Expected type of value was int, got %s", bodySpec["value"])
}
}
func TestBodySpecFromStruct(t *testing.T) {
type X struct {
FloatArg float32 `json:"float_arg"`
}
type Y struct {
Original int `json:"original_value"`
Sum int32 `json:"value_plus_one"`
StrArg string `json:"str_arg"`
BoolArg bool `json:"bool_arg"`
StructArg X `json:"struct_arg"`
}
bodySpec := BodySpecFromStruct(Y{})
if bodySpec["original_value"].Type != "int" {
t.Errorf("Expected type of original_value was int, got %s", bodySpec["original_value"])
}
if bodySpec["value_plus_one"].Type != "int32" {
t.Errorf("Expected type of value_plus_one was int32, got %s", bodySpec["value_plus_one"])
}
if bodySpec["str_arg"].Type != "string" {
t.Errorf("Expected type of str_arg was string, got %s", bodySpec["str_arg"])
}
if bodySpec["bool_arg"].Type != "bool" {
t.Errorf("Expected type of bool_arg was bool, got %s", bodySpec["bool_arg"])
}
if bodySpec["struct_arg"].Body["float_arg"].Type != "float32" {
t.Errorf("Expected type of struct_arg/float_arg was float32, got %s", bodySpec["struct_arg"].Body["float_arg"].Type)
}
}