From 7b52d0b56a23b6a330199332f4cd9269e132264c Mon Sep 17 00:00:00 2001 From: Gani Georgiev Date: Thu, 23 Oct 2025 11:12:00 +0300 Subject: [PATCH] [#7267] added tests.ApiScenario.DisableTestAppCleanup optional field --- CHANGELOG.md | 4 +++- tests/api.go | 14 +++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e7d0a4b7..9c34306e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,11 @@ -## v0.30.5 (WIP) +## v0.31.0 (WIP) - Visualize presentable multiple `relation` fields ([#7260](https://github.com/pocketbase/pocketbase/issues/7260)). - Support Ed25519 in the optional OIDC id_token signature validation ([#7252](https://github.com/pocketbase/pocketbase/issues/7252); thanks @shynome). +- Added `tests.ApiScenario.DisableTestAppCleanup` optional field to skip the auto test app cleanup and leave it up to the developers ([#7267](https://github.com/pocketbase/pocketbase/discussions/7267)). + ## v0.30.4 diff --git a/tests/api.go b/tests/api.go index 2fa281ec..35d2928d 100644 --- a/tests/api.go +++ b/tests/api.go @@ -48,6 +48,14 @@ type ApiScenario struct { // A zero or negative value means that there will be no timeout. Timeout time.Duration + // DisableTestAppCleanup disables the builtin TestApp cleanup at + // the end of the ApiScenario execution. + // + // This option works only when explicit TestAppFactory is specified + // and means that the developer is responsible to do the necessary + // after test cleanup on their own (e.g. by manually calling testApp.Cleanup()). + DisableTestAppCleanup bool + // expectations // --------------------------------------------------------------- @@ -172,7 +180,11 @@ func (scenario *ApiScenario) test(t testing.TB) { t.Fatalf("Failed to initialize the test app instance: %v", testAppErr) } } - defer testApp.Cleanup() + + // https://github.com/pocketbase/pocketbase/discussions/7267 + if scenario.TestAppFactory == nil || !scenario.DisableTestAppCleanup { + defer testApp.Cleanup() + } baseRouter, err := apis.NewRouter(testApp) if err != nil {