Exemple #1
0
func (me *datasetTest) TestDeleteSqlWithOrder() {
	t := me.T()
	mDb, _, _ := sqlmock.New()
	ds1 := New("order", mDb).From("items")
	sql, _, err := ds1.Order(I("name").Desc()).ToDeleteSql()
	assert.Nil(t, err)
	assert.Equal(t, sql, `DELETE FROM "items" ORDER BY "name" DESC`)
}
Exemple #2
0
func (me *datasetTest) TestDeleteSqlWithLimit() {
	t := me.T()
	mDb, _, _ := sqlmock.New()
	ds1 := New("limit", mDb).From("items")
	sql, _, err := ds1.Limit(10).ToDeleteSql()
	assert.Nil(t, err)
	assert.Equal(t, sql, `DELETE FROM "items" LIMIT 10`)
}
Exemple #3
0
func (me *datasetTest) TestUpdateSqlWithOrder() {
	t := me.T()
	mDb, _, _ := sqlmock.New()
	ds1 := New("order", mDb).From("items")
	type item struct {
		Address string `db:"address"`
		Name    string `db:"name"`
	}
	sql, _, err := ds1.Order(I("name").Desc()).ToUpdateSql(item{Name: "Test", Address: "111 Test Addr"})
	assert.Nil(t, err)
	assert.Equal(t, sql, `UPDATE "items" SET "address"='111 Test Addr',"name"='Test' ORDER BY "name" DESC`)
}
Exemple #4
0
func (me *datasetTest) TestUpdateSqlWithLimit() {
	t := me.T()
	mDb, _, _ := sqlmock.New()
	ds1 := New("limit", mDb).From("items")
	type item struct {
		Address string `db:"address"`
		Name    string `db:"name"`
	}
	sql, _, err := ds1.Limit(10).ToUpdateSql(item{Name: "Test", Address: "111 Test Addr"})
	assert.Nil(t, err)
	assert.Equal(t, sql, `UPDATE "items" SET "address"='111 Test Addr',"name"='Test' LIMIT 10`)
}
Exemple #5
0
func TestSuiteLogging(t *testing.T) {
	testT := testing.T{}

	suiteLoggingTester := new(SuiteLoggingTester)

	capture := StdoutCapture{}
	capture.StartCapture()
	Run(&testT, suiteLoggingTester)
	output, err := capture.StopCapture()

	assert.Nil(t, err, "Got an error trying to capture stdout!")

	// Failed tests' output is always printed
	assert.Contains(t, output, "TESTLOGFAIL")

	if testing.Verbose() {
		// In verbose mode, output from successful tests is also printed
		assert.Contains(t, output, "TESTLOGPASS")
	} else {
		assert.NotContains(t, output, "TESTLOGPASS")
	}
}
Exemple #6
0
func Test_Mock_Return_Times(t *testing.T) {

	// make a test impl object
	var mockedService *TestExampleImplementation = new(TestExampleImplementation)

	mockedService.On("TheExampleMethod", "A", "B", true).Return(1, "two", true).Times(5)

	// ensure the call was created
	if assert.Equal(t, 1, len(mockedService.ExpectedCalls)) {
		call := mockedService.ExpectedCalls[0]

		assert.Equal(t, "TheExampleMethod", call.Method)
		assert.Equal(t, "A", call.Arguments[0])
		assert.Equal(t, "B", call.Arguments[1])
		assert.Equal(t, true, call.Arguments[2])
		assert.Equal(t, 1, call.ReturnArguments[0])
		assert.Equal(t, "two", call.ReturnArguments[1])
		assert.Equal(t, true, call.ReturnArguments[2])
		assert.Equal(t, 5, call.Repeatability)
		assert.Nil(t, call.WaitFor)

	}

}
Exemple #7
0
// Nil asserts that the specified object is nil.
//
//    require.Nil(t, err, "err should be nothing")
func Nil(t TestingT, object interface{}, msgAndArgs ...interface{}) {
	if !assert.Nil(t, object, msgAndArgs...) {
		t.FailNow()
	}
}