-
Notifications
You must be signed in to change notification settings - Fork 2
/
example_test.go
36 lines (31 loc) · 834 Bytes
/
example_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
package mongotest_test
import (
"fmt"
"github.com/pinzolo/mongotest"
)
func Example() {
mongotest.Configure(mongotest.Config{
URL: "mongodb://root:[email protected]:27017",
Database: "mongotest",
FixtureRootDir: "testdata",
FixtureFormat: mongotest.FixtureFormatJSON,
PreInsertFuncs: []mongotest.PreInsertFunc{
mongotest.SimpleConvertTime("users", "created_at"),
},
})
// 1. Read testdata/json/admin_users.json and testdata/json/foo_users.json
// 2. Merge read data
// 3. Drop collection and insert read data
err := mongotest.UseFixture("json/admin_users", "json/foo_users")
if err != nil {
panic(err)
}
// Count is helper function.
// mongotest has some useful helper functions.
n, err := mongotest.Count("users")
if err != nil {
panic(err)
}
fmt.Println(n)
// Output: 3
}