test: preserve fixture errors and verify complete certificate pools (#2462)

This commit is contained in:
user01010111
2026-09-29 11:23:15 +13:00
committed by GitHub
parent 62f8a39c8a
commit c556dc478d
7 changed files with 51 additions and 91 deletions

View File

@@ -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

View File

@@ -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")
}