6
6
7
7
"gopkg.in/mgo.v2/bson"
8
8
9
- "github.com/stretchr/testify/assert"
10
-
11
9
mongo "github.com/rs/rest-layer-mongo"
12
10
)
13
11
@@ -17,36 +15,56 @@ const (
17
15
)
18
16
19
17
func TestObjectIDValidate (t * testing.T ) {
20
-
21
18
v := & mongo.ObjectID {}
22
19
23
20
t .Run ("validObjectID" , func (t * testing.T ) {
21
+ expect := bson .ObjectIdHex (validObjectID )
24
22
id , err := v .Validate (validObjectID )
25
- assert .Equal (t , bson .ObjectIdHex (validObjectID ), id , "v.Validate(validObjectID)" )
26
- assert .NoError (t , err , "v.Validate(validObjectID)" )
23
+ if expect != id {
24
+ t .Errorf ("v.Validate(validObjectID):\n %v (expect) != %v (actual)" , expect , id )
25
+ }
26
+ if err != nil {
27
+ t .Error ("v.Validate(validObjectID):\n unexpected error:" , err )
28
+ }
27
29
})
28
30
29
31
t .Run ("invalidObjectID" , func (t * testing.T ) {
30
32
id , err := v .Validate (invalidObjectID )
31
- assert .Nil (t , id , "v.Validate(invalidObjectID)" )
32
- assert .Error (t , err , "v.Validate(invalidObjectID)" )
33
+ if nil != id {
34
+ t .Errorf ("v.Validate(invalidObjectID):\n %v (expect) != %v (actual)" , nil , id )
35
+ }
36
+ if err == nil {
37
+ t .Error ("v.Validate(invalidObjectID):\n expected error, got nil" )
38
+ }
33
39
})
34
40
}
35
41
36
42
func TestObjectIDJSONSchmea (t * testing.T ) {
37
-
38
43
v := & mongo.ObjectID {}
39
44
m , err := v .BuildJSONSchema ()
40
- assert .NoError (t , err )
41
- assert .Equal (t , m ["type" ], "string" )
45
+ if err != nil {
46
+ t .Error ("_, err := v.BuildJSONSchema():\n unexpected error:" , err )
47
+ }
48
+ if m == nil {
49
+ t .Fatal ("m, _ := v.BuildJSONSchema():\n expected m not to be nil" )
50
+ }
51
+ if s := m ["type" ]; s != "string" {
52
+ t .Fatalf ("m, _ := v.BuildJSONSchema(); m[\" type\" ]\n %v (expected) != %v (actual)" , "string" , s )
53
+ }
42
54
re , err := regexp .Compile (m ["pattern" ].(string ))
43
- assert .NoError (t , err )
55
+ if err != nil {
56
+ t .Fatal ("_, err := regexp.Compile(m[\" type\" ]);\n unexpected error:" , m , err )
57
+ }
44
58
45
59
t .Run ("validObjectID" , func (t * testing.T ) {
46
- assert .True (t , re .MatchString (validObjectID ), "re.Match(validObjectID)" )
60
+ if match := re .MatchString (validObjectID ); ! match {
61
+ t .Errorf ("re.MatchString(validObjectID)\n %v (expected) != %v (actual)" , true , match )
62
+ }
47
63
})
48
64
49
65
t .Run ("invalidObjectID" , func (t * testing.T ) {
50
- assert .False (t , re .MatchString (invalidObjectID ), "re.Match(invalidObjectID)" )
66
+ if match := re .MatchString (invalidObjectID ); match {
67
+ t .Errorf ("re.MatchString(invalidObjectID)\n %v (expected) != %v (actual)" , false , match )
68
+ }
51
69
})
52
70
}
0 commit comments