-
Notifications
You must be signed in to change notification settings - Fork 0
/
util_test.go
51 lines (41 loc) · 1.09 KB
/
util_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
package mgm_test
import (
"github.com/kamva/mgm/v3"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"testing"
)
func TestGetModelCollection(t *testing.T) {
setupDefConnection()
doc := &Doc{}
coll := mgm.Coll(doc)
name := mgm.CollName(doc)
require.Equal(t, coll.Name(), name, "Expected doc's collection , got %v")
}
func TestGetDefaultCollName(t *testing.T) {
type Book struct {
mgm.DefaultModel `bson:",inline"`
}
type BlogPost struct {
mgm.DefaultModel `bson:",inline"`
}
require.Equal(t, "books", mgm.CollName(&Book{}))
require.Equal(t, "blog_posts", mgm.CollName(&BlogPost{}))
}
type User struct {
mgm.DefaultModel `bson:",inline"`
}
func (user *User) CollectionName() string {
return "my_users"
}
func TestGetSpecifiedCollName(t *testing.T) {
require.Equal(t, "my_users", mgm.CollName(&User{}))
}
func TestUpsertTrueOption(t *testing.T) {
option := mgm.UpsertTrueOption()
upsert := true
assert.Equal(t, option.Upsert, &upsert)
assert.Nil(t, option.ArrayFilters)
assert.Nil(t, option.BypassDocumentValidation)
assert.Nil(t, option.Collation)
}