func TestModelInitialize(t *testing.T) {
	mock := &MockMongoModel{Name: "Mogi"}
	mock.Initialize()

	test.AssertEqual(t, mock.Name, "Mogi")
	test.AssertNotEqual(t, mock.GetId(), nil)
	test.AssertTypeMatch(t, mock.GetId(), bson.NewObjectId())
	test.AssertTypeMatch(t, mock.GetUpdated(), time.Now())
	test.AssertTypeMatch(t, mock.GetCreated(), time.Now())
}
Example #2
0
func TestNewSession(t *testing.T) {
	newSession := TestGateway.NewSession()
	test.AssertTypeMatch(t, newSession, &mgo.Session{})

	err := newSession.Ping()
	test.AssertEqual(t, err, nil)
}
Example #3
0
func TestGatewayInitialize(t *testing.T) {
	err := TestGateway.Initialize()
	test.AssertEqual(t, err, nil)

	buildInfo, err := TestGateway.BaseSession.BuildInfo()
	test.AssertEqual(t, err, nil)
	test.AssertTypeMatch(t, buildInfo.Version, "2.6.whatever")
}
Example #4
0
func TestFindAll(t *testing.T) {
	resetDb()

	thing1 := &MockMongoModel{Name: "Thing 1"}
	thing2 := &MockMongoModel{Name: "Thing 2"}
	thing1.Initialize()
	thing2.Initialize()
	insertTestFixture(thing1)
	insertTestFixture(thing2)

	modelsInterface, err := TestGateway.FindAll(&MockMongoModel{})
	models := *modelsInterface.(*[]*MockMongoModel)
	test.AssertEqual(t, err, nil)
	test.AssertEqual(t, len(models), 2)
	test.AssertTypeMatch(t, models, []*MockMongoModel{thing1, thing2})
}
Example #5
0
func TestFindAllBy(t *testing.T) {
	resetDb()

	thing1 := &MockMongoModel{Name: "Thing"}
	thing2 := &MockMongoModel{Name: "Thing"}
	thing3 := &MockMongoModel{Name: "Bob"}
	thing1.Initialize()
	thing2.Initialize()
	thing3.Initialize()
	insertTestFixture(thing1)
	insertTestFixture(thing2)
	insertTestFixture(thing3)

	modelsInterface, err := TestGateway.FindAllBy(&MockMongoModel{}, Query{Conditions: map[string]interface{}{"name": "Thing"}})
	models := *modelsInterface.(*[]*MockMongoModel)
	test.AssertEqual(t, err, nil)
	test.AssertEqual(t, len(models), 2)
	test.AssertTypeMatch(t, models, []*MockMongoModel{thing1, thing2})
	// Todo: extend this test to hit order, offset and limit
}