Esempio n. 1
0
func LoadFixtures(fixtures Fixtures) {

	if db == nil {
		Start()
	}

	if !isTesting {
		panic("Not in testing")
	}

	for tableName, rows := range fixtures {
		_, err := db.Exec(fmt.Sprintf("TRUNCATE %s", tableName))
		util.MaybePanic(err)

		for _, row := range rows {
			columns, values := getColumnsAndValues(row)
			query := fmt.Sprintf(
				fixtureQueryFmt, tableName,
				columns, commaSeparatedPlaceHolders(len(values)),
			)

			_, err := db.Exec(query, values...)
			if err != nil {
				util.MaybePanic(err)
			}
		}
	}
}
Esempio n. 2
0
func TruncateOrPanic(tableNames []string) {
	if !isTesting {
		panic("You can not truncate if you are not testing!")
	}

	for _, t := range tableNames {
		_, err := db.Exec(fmt.Sprintf("TRUNCATE %s", t))
		util.MaybePanic(err)
	}
}