-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwriteData_test.go
63 lines (52 loc) · 1.29 KB
/
writeData_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
package sqlbuilder
import (
. "github.com/smartystreets/goconvey/convey"
"testing"
)
type Person struct {
ID int64 `db:"id"`
FirstName string `db:"first_name"`
Birthday string
Pointer *int `db:"pointer"`
}
func TestGetData(t *testing.T) {
person := &Person{10, "Testy", "1/1/1988", nil}
Convey("getData", t, func() {
Convey("success - struct", func() {
data, err := getData(person)
So(err, ShouldBeNil)
So(len(data), ShouldEqual, 4)
So(data["id"], ShouldEqual, 10)
So(data["first_name"], ShouldEqual, "Testy")
So(data["Birthday"], ShouldEqual, "1/1/1988")
So(data["pointer"], ShouldBeNil)
})
Convey("success - map", func() {
data, err := getData(map[string]int{
"a": 1,
"b": 2,
"c": 3,
})
So(err, ShouldBeNil)
So(len(data), ShouldEqual, 3)
So(data["a"], ShouldEqual, 1)
So(data["b"], ShouldEqual, 2)
So(data["c"], ShouldEqual, 3)
// We explicitly cannot test the order because that's the nature of go maps
})
Convey("failure - invalid map", func() {
data, err := getData(map[int]string{
1: "a",
2: "b",
3: "c",
})
So(err, ShouldNotBeNil)
So(data, ShouldBeNil)
})
Convey("failure - invalid argument", func() {
data, err := getData(10)
So(err, ShouldNotBeNil)
So(data, ShouldBeNil)
})
})
}