-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmongo_test.go
49 lines (42 loc) · 1.01 KB
/
mongo_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
package main
import (
"testing"
"gopkg.in/mgo.v2/bson"
)
// TestMongoInsert
func TestMongoInsert(t *testing.T) {
initMetaDataService()
// our db attributes
dbname := "ml"
collname := "metadata"
// remove all records in test collection
MongoRemove(dbname, collname, bson.M{})
// insert one record
var records []Record
var err error
rec := Record{
Model: "model",
Type: "type",
Version: "version",
Description: "description",
Reference: "reference",
Discipline: "domains",
Bundle: "bundle",
UserName: "user",
UserID: "id",
Provider: "provider",
}
records = append(records, rec)
MongoInsert(dbname, collname, records)
// look-up one record
spec := bson.M{"model": "model"}
idx := 0
limit := 1
records, err = MongoGet(dbname, collname, spec, idx, limit)
if err != nil {
t.Errorf("unable to find records using spec '%s', error %v", spec, err)
}
if len(records) != 1 {
t.Errorf("wrong number of records using spec '%s', records %+v", spec, records)
}
}