chore(test): show table content when db assertion failed
This commit is contained in:
parent
abe5f72493
commit
017f771783
@ -17,6 +17,7 @@
|
|||||||
package db
|
package db
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
@ -93,7 +94,16 @@ func AssertExists(t *testing.T, table string, values map[string]interface{}, cus
|
|||||||
exists, err = x.Table(table).Where(values).Get(&v)
|
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.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
|
// AssertMissing checks and asserts the nonexiste nce of certain entries in the db
|
||||||
|
Loading…
x
Reference in New Issue
Block a user