-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathdocument_test.go
53 lines (40 loc) · 1.05 KB
/
document_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
package colt
import (
"github.com/stretchr/testify/assert"
"go.mongodb.org/mongo-driver/bson/primitive"
"strings"
"testing"
)
type todo struct {
Doc `bson:",inline"`
Title string `bson:"title" json:"title"`
}
func TestCDocument_SetID(t *testing.T) {
doc := todo{}
doc.SetID("638cda03871d719a9020c855")
assert.Equal(t, doc.ID, "638cda03871d719a9020c855")
}
func TestCDocument_GetID(t *testing.T) {
doc := todo{}
assert.Empty(t, doc.GetID())
doc.SetID("638cda03871d719a9020c855")
assert.Equal(t, doc.ID, "638cda03871d719a9020c855")
}
func TestCDocument_NewID(t *testing.T) {
doc := todoWithCustomId{}
assert.Empty(t, doc.GetID())
assert.NotEmpty(t, doc.NewID())
}
type todoWithCustomId struct {
Doc `bson:",inline"`
Title string `bson:"title" json:"title"`
}
func (t *todoWithCustomId) NewID() string {
return "td_" + primitive.NewObjectID().Hex()
}
func TestCDocument_NewID_Custom(t *testing.T) {
doc := todoWithCustomId{}
assert.Empty(t, doc.GetID())
assert.NotEmpty(t, doc.NewID())
assert.True(t, strings.HasPrefix(doc.NewID(), "td_"))
}