forked from go-bongo/bongo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
70 lines (44 loc) · 1.27 KB
/
main_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
package bongo
import (
"encoding/json"
"errors"
// "fmt"
. "gopkg.in/check.v1"
)
func (s *TestSuite) TestConnect(c *C) {
connection := new(Connection)
connection.Config = config
connection.Connect()
defer connection.Session.Close()
err := connection.Session.Ping()
c.Assert(err, Equals, nil)
connection.Session.DB(config.Database).DropDatabase()
}
func (s *TestSuite) TestRegister(c *C) {
connection := new(Connection)
connection.Config = config
connection.Connect()
connection.Register(&FooBar{}, "foo_bar")
indexes, err := connection.Collection("foo_bar").Collection().Indexes()
c.Assert(err, Equals, nil)
c.Assert(len(indexes), Equals, 2)
c.Assert(indexes[0].Key[0], Equals, "_id")
c.Assert(indexes[1].Key[0], Equals, "count")
}
type errorHolder struct {
Err *SaveResult
}
func (s *TestSuite) TestMarshalResult(c *C) {
err := NewSaveResult(false, errors.New("Failed to save"))
holder := &errorHolder{
Err: err,
}
marshaled, e := json.Marshal(holder)
c.Assert(e, IsNil)
c.Assert(string(marshaled), Equals, `{"Err":"Failed to save"}`)
holder.Err.ValidationErrors = []string{"foo", "bar"}
marshaled, e = json.Marshal(holder)
c.Assert(e, IsNil)
c.Assert(string(marshaled), Equals, `{"Err":["foo","bar"]}`)
// fmt.Println(string(marshaled))
}