-
Notifications
You must be signed in to change notification settings - Fork 4
/
properties_test.go
92 lines (60 loc) · 1.73 KB
/
properties_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
package xray_test
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/pieterclaerhout/go-xray"
)
type sampleStruct struct {
Name string `form:"name" json:"name"`
Title string `form:"title" json:"title"`
}
func TestPropertiesValid(t *testing.T) {
actual, err := xray.Properties(sampleStruct{
Name: "Property Name",
Title: "Property Title",
})
assert.NoError(t, err, "error")
assert.NotNil(t, actual)
assert.Equal(t, []string([]string{"Name", "Title"}), actual)
}
func TestPropertiesInvalidType(t *testing.T) {
actual, err := xray.Properties(1)
assert.Error(t, err, "error")
assert.Nil(t, actual)
}
func TestPropertiesAsMapValid(t *testing.T) {
actual, err := xray.PropertiesAsMap(sampleStruct{
Name: "Map Name",
Title: "Map Title",
})
assert.NoError(t, err, "error")
assert.NotNil(t, actual)
assert.Equal(t, map[string]interface{}(map[string]interface{}{"Name": "Map Name", "Title": "Map Title"}), actual)
}
func TestPropertiesAsMapInvalidType(t *testing.T) {
actual, err := xray.PropertiesAsMap(1)
assert.Error(t, err, "error")
assert.Equal(t, map[string]interface{}{}, actual)
}
func TestPropertyValid(t *testing.T) {
actual, err := xray.Property(sampleStruct{
Name: "Valid Name",
Title: "Valid Title",
}, "Name")
assert.NoError(t, err, "error")
assert.NotNil(t, actual)
assert.Equal(t, "Valid Name", actual)
}
func TestPropertyNonExistingPropery(t *testing.T) {
actual, err := xray.Property(sampleStruct{
Name: "Unknown Name",
Title: "Unknonw Title",
}, "UnknownProperty")
assert.Error(t, err, "error")
assert.Nil(t, actual)
}
func TestPropertyInvalidType(t *testing.T) {
actual, err := xray.Property(1, "a")
assert.Error(t, err, "error")
assert.Equal(t, nil, actual)
}