-
Notifications
You must be signed in to change notification settings - Fork 40
/
validate_test.go
43 lines (33 loc) · 1.2 KB
/
validate_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
package bongo
import (
. "github.com/smartystreets/goconvey/convey"
"github.com/globalsign/mgo/bson"
"testing"
)
func TestValidation(t *testing.T) {
Convey("Validation", t, func() {
Convey("ValidateRequired()", func() {
So(ValidateRequired("foo"), ShouldEqual, true)
So(ValidateRequired(""), ShouldEqual, false)
So(ValidateRequired(0), ShouldEqual, false)
So(ValidateRequired(1), ShouldEqual, true)
})
Convey("ValidateInclusionIn()", func() {
So(ValidateInclusionIn("foo", []string{"foo", "bar", "baz"}), ShouldEqual, true)
So(ValidateInclusionIn("bing", []string{"foo", "bar", "baz"}), ShouldEqual, false)
})
Convey("ValidateMongoIdRef()", func() {
connection := getConnection()
defer func() {
connection.Session.DB("bongotest").DropDatabase()
}()
// Make the doc
doc := &noHookDocument{}
err := connection.Collection("docs").Save(doc)
So(err, ShouldEqual, nil)
So(ValidateMongoIdRef(doc.Id, connection.Collection("docs")), ShouldEqual, true)
So(ValidateMongoIdRef(bson.NewObjectId(), connection.Collection("docs")), ShouldEqual, false)
So(ValidateMongoIdRef(bson.NewObjectId(), connection.Collection("other_collection")), ShouldEqual, false)
})
})
}