Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f301bb2

Browse files
committed
Dropped dependency on testify from id_test.go
1 parent 2b3d0c5 commit f301bb2

File tree

1 file changed

+31
-13
lines changed

1 file changed

+31
-13
lines changed

id_test.go

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import (
66

77
"gopkg.in/mgo.v2/bson"
88

9-
"github.com/stretchr/testify/assert"
10-
119
mongo "github.com/rs/rest-layer-mongo"
1210
)
1311

@@ -17,36 +15,56 @@ const (
1715
)
1816

1917
func TestObjectIDValidate(t *testing.T) {
20-
2118
v := &mongo.ObjectID{}
2219

2320
t.Run("validObjectID", func(t *testing.T) {
21+
expect := bson.ObjectIdHex(validObjectID)
2422
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+
}
2729
})
2830

2931
t.Run("invalidObjectID", func(t *testing.T) {
3032
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+
}
3339
})
3440
}
3541

3642
func TestObjectIDJSONSchmea(t *testing.T) {
37-
3843
v := &mongo.ObjectID{}
3944
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+
}
4254
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+
}
4458

4559
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+
}
4763
})
4864

4965
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+
}
5169
})
5270
}

0 commit comments

Comments
 (0)