mirror of
https://github.com/henrygd/beszel.git
synced 2026-09-30 19:56:21 +00:00
test: preserve fixture errors and verify complete certificate pools (#2462)
This commit is contained in:
@@ -112,6 +112,9 @@ func CreateRecord(app core.App, collectionName string, fields map[string]any) (*
|
||||
|
||||
func ClearCollection(t testing.TB, app core.App, collectionName string) error {
|
||||
_, err := app.DB().NewQuery(fmt.Sprintf("DELETE from %s", collectionName)).Execute()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
recordCount, err := app.CountRecords(collectionName)
|
||||
assert.EqualValues(t, recordCount, 0, "should have 0 records after clearing")
|
||||
return err
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
//go:build testing
|
||||
|
||||
package tests
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestClearCollection(t *testing.T) {
|
||||
hub, err := NewTestHub(t.TempDir())
|
||||
require.NoError(t, err)
|
||||
defer hub.Cleanup()
|
||||
|
||||
_, err = CreateUser(hub, "clear@example.com", "password123")
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, ClearCollection(t, hub, "users"))
|
||||
|
||||
// An empty view can be counted, but SQLite rejects DELETE against it.
|
||||
view := core.NewViewCollection("empty_users")
|
||||
view.ViewQuery = "SELECT id FROM users"
|
||||
require.NoError(t, hub.Save(view))
|
||||
require.ErrorContains(t, ClearCollection(t, hub, "empty_users"), "cannot modify empty_users because it is a view")
|
||||
}
|
||||
Reference in New Issue
Block a user