56 lines
1.3 KiB
Go
56 lines
1.3 KiB
Go
package repositories
|
|
|
|
import (
|
|
. "github.com/smartystreets/goconvey/convey"
|
|
_ "github.com/deluan/gosonic/tests"
|
|
"testing"
|
|
"github.com/deluan/gosonic/tests"
|
|
)
|
|
|
|
const (
|
|
testCollectionName = "TestCollection"
|
|
)
|
|
|
|
func TestCreateCollection(t *testing.T) {
|
|
tests.Init(t, true)
|
|
|
|
Convey("Given an empty DB", t, func() {
|
|
|
|
Convey("When creating a new collection", func() {
|
|
newCol := createCollection(testCollectionName)
|
|
|
|
Convey("Then it should create the collection", func() {
|
|
So(dbInstance().Use(testCollectionName), ShouldNotBeNil)
|
|
})
|
|
Convey("And it should create a default index on Id", func() {
|
|
allIndexes := newCol.AllIndexes()
|
|
So(len(allIndexes), ShouldEqual, 1)
|
|
So(len(allIndexes[0]), ShouldEqual, 1)
|
|
So(allIndexes[0], ShouldContain, "Id")
|
|
})
|
|
})
|
|
|
|
Convey("When creating a new collection with a 'Name' index", func() {
|
|
newCol := createCollection(testCollectionName, "Name")
|
|
|
|
Convey("Then it should create a default index [Id] and an index on 'Name'", func() {
|
|
listOfIndexes := newCol.AllIndexes()
|
|
|
|
So(len(listOfIndexes), ShouldEqual, 2)
|
|
|
|
var allPaths = make(map[string]bool)
|
|
for _, i := range listOfIndexes {
|
|
allPaths[i[0]] = true
|
|
}
|
|
|
|
So(allPaths, ShouldContainKey, "Id")
|
|
So(allPaths, ShouldContainKey, "Name")
|
|
})
|
|
})
|
|
|
|
Reset(func() {
|
|
dbInstance().Drop(testCollectionName)
|
|
})
|
|
})
|
|
|
|
} |