-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtesting.go
60 lines (47 loc) · 1.1 KB
/
testing.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
package main
import (
"fmt"
"reflect"
"testing"
"gopkg.in/mgo.v2/bson"
)
/* Test Helper */
func Expect(t *testing.T, a interface{}, b interface{}) {
if a != b {
t.Errorf("Expected ||%#v|| (type %v) - Got ||%#v|| (type %v)", b, reflect.TypeOf(b), a, reflect.TypeOf(a))
}
}
func ExpectNotNil(t *testing.T, a interface{}) {
if a == nil {
t.Errorf("Expected ||not nil|| - Got ||nil|| (type %v)", reflect.TypeOf(a))
}
}
type HandlerTest struct {
Session *Dao
Entries map[string]Palindrome
}
func (h *HandlerTest) SetupTest(f func()) {
settings := GetSettings()
settings.DbName = "test"
dao := NewDao(settings)
dao.EnsureIndex()
defer dao.Close()
c := dao.Database().C("palindromes")
h.Entries = make(map[string]Palindrome)
h.Session = dao
var palindrome Palindrome
for i := 0; i < 10; i++ {
palindrome = Palindrome{
ID: bson.NewObjectId(),
Phrase: fmt.Sprintf("test phrase %d", i),
}
c.Insert(&palindrome)
h.Entries[palindrome.ID.Hex()] = palindrome
}
f()
h.tearDown()
}
func (h *HandlerTest) tearDown() {
c := h.Session.Database().C("palindromes")
c.RemoveAll(bson.M{})
}