Beispiel #1
0
// RowExists asserts row exists in a table.
func RowExists(t assert.Tester, tableName, pkName, selectValue interface{}) ([]mysql.Row, mysql.Result) {
	value := fmt.Sprintf("%v", selectValue)
	if _, ok := selectValue.(string); ok {
		value = "'" + dbcon.Escape(value) + "'"
	}
	rows, res, err := dbcon.Query("SELECT * FROM %s WHERE %s = %s", tableName, pkName, value)
	assert.NotError(t, err, assert.NESTING_2, assert.FAIL_FAST)
	assert.T(t, len(rows) > 0, assert.NESTING_2, assert.FAIL_FAST, "Expected row with %s = %s to exist in the table %s.", pkName, value, tableName)
	return rows, res
}
Beispiel #2
0
// LoadFixture loads fixture to database
func LoadFixture(t assert.Tester, fixturePath string) {
	sql_lines := assert.LoadFixture(t, fixturePath)
	assert.T(t, len(sql_lines) > 0)
	for _, sql := range sql_lines {
		if strings.HasPrefix(sql, "--") || sql == "" {
			continue
		}
		if _, _, err := dbcon.Query(sql); err != nil {
			assert.NotError(t, err, assert.NESTING_2)
		}
	}
}
Beispiel #3
0
// TableNotEmpty asserts tableName is not empty.
func TableNotEmpty(t assert.Tester, tableName string) {
	rowCount, err := GetTableRowCount(tableName)
	assert.NotError(t, err, assert.NESTING_2)
	assert.T(t, rowCount > 0, assert.NESTING_2, "Expected table to have data.")
}
Beispiel #4
0
// TableDoesNotExists asserts MySQL table does not exists in the database.
func TableDoesNotExists(t assert.Tester, tableName string) {
	foundTable := tableExists(tableName)
	assert.T(t, !foundTable, assert.NESTING_2, "Table '%s' is present in the database.", tableName)
}