From dbbc99c581fa978550db180ffd2df8ca4e471fd1 Mon Sep 17 00:00:00 2001 From: kolaente Date: Fri, 13 Jan 2023 18:33:43 +0100 Subject: [PATCH] chore(test): show table content when db assertion failed --- pkg/db/test.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/pkg/db/test.go b/pkg/db/test.go index 9ebc8c3dc..329abbc3a 100644 --- a/pkg/db/test.go +++ b/pkg/db/test.go @@ -17,6 +17,7 @@ package db import ( + "encoding/json" "fmt" "os" "testing" @@ -92,7 +93,16 @@ func AssertExists(t *testing.T, table string, values map[string]interface{}, cus exists, err = x.Table(table).Where(values).Get(&v) } assert.NoError(t, err, fmt.Sprintf("Failed to assert entries exist in db, error was: %s", err)) - assert.True(t, exists, fmt.Sprintf("Entries %v do not exist in table %s", values, table)) + if !exists { + + all := []map[string]interface{}{} + err = x.Table(table).Find(&all) + assert.NoError(t, err, fmt.Sprintf("Failed to assert entries exist in db, error was: %s", err)) + pretty, err := json.MarshalIndent(all, "", " ") + assert.NoError(t, err, fmt.Sprintf("Failed to assert entries exist in db, error was: %s", err)) + + t.Errorf(fmt.Sprintf("Entries %v do not exist in table %s\n\nFound entries instead: %v", values, table, string(pretty))) + } } // AssertMissing checks and asserts the nonexiste nce of certain entries in the db