From fc5703ac8cbaa3cfbca8957977dd5f8134b3ab44 Mon Sep 17 00:00:00 2001 From: kolaente Date: Thu, 3 Jun 2021 15:30:31 +0200 Subject: [PATCH] Add truncate parameter to test fixtures setup --- pkg/db/dump.go | 3 +++ pkg/routes/api/v1/testing.go | 8 +++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/pkg/db/dump.go b/pkg/db/dump.go index faf54026314..334b4d1ed70 100644 --- a/pkg/db/dump.go +++ b/pkg/db/dump.go @@ -47,6 +47,9 @@ func Dump() (data map[string][]byte, err error) { // Restore restores a table with all its entries func Restore(table string, contents []map[string]interface{}) (err error) { + if _, err := x.IsTableExist(table); err != nil { + return err + } for _, content := range contents { if _, err := x.Table(table).Insert(content); err != nil { diff --git a/pkg/routes/api/v1/testing.go b/pkg/routes/api/v1/testing.go index ac4b4ff0f3b..ac81a44a38b 100644 --- a/pkg/routes/api/v1/testing.go +++ b/pkg/routes/api/v1/testing.go @@ -58,7 +58,13 @@ func HandleTesting(c echo.Context) error { }) } - err = db.RestoreAndTruncate(table, content) + truncate := c.QueryParam("truncate") + if truncate == "true" || truncate == "" { + err = db.RestoreAndTruncate(table, content) + } else { + err = db.Restore(table, content) + } + if err != nil { return c.JSON(http.StatusInternalServerError, map[string]interface{}{ "error": true,