Add truncate parameter to test fixtures setup
This commit is contained in:
parent
3277f6acf7
commit
fc5703ac8c
2 changed files with 10 additions and 1 deletions
|
@ -47,6 +47,9 @@ func Dump() (data map[string][]byte, err error) {
|
||||||
|
|
||||||
// Restore restores a table with all its entries
|
// Restore restores a table with all its entries
|
||||||
func Restore(table string, contents []map[string]interface{}) (err error) {
|
func Restore(table string, contents []map[string]interface{}) (err error) {
|
||||||
|
if _, err := x.IsTableExist(table); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
for _, content := range contents {
|
for _, content := range contents {
|
||||||
if _, err := x.Table(table).Insert(content); err != nil {
|
if _, err := x.Table(table).Insert(content); err != nil {
|
||||||
|
|
|
@ -58,7 +58,13 @@ func HandleTesting(c echo.Context) error {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
truncate := c.QueryParam("truncate")
|
||||||
|
if truncate == "true" || truncate == "" {
|
||||||
err = db.RestoreAndTruncate(table, content)
|
err = db.RestoreAndTruncate(table, content)
|
||||||
|
} else {
|
||||||
|
err = db.Restore(table, content)
|
||||||
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusInternalServerError, map[string]interface{}{
|
return c.JSON(http.StatusInternalServerError, map[string]interface{}{
|
||||||
"error": true,
|
"error": true,
|
||||||
|
|
Loading…
Reference in a new issue