@@ -24,10 +24,83 @@ import (
2424 "github.com/supabase/cli/internal/testing/apitest"
2525 "github.com/supabase/cli/internal/testing/fstest"
2626 "github.com/supabase/cli/internal/utils"
27+ "github.com/supabase/cli/pkg/config"
2728 "github.com/supabase/cli/pkg/pgtest"
2829 "github.com/supabase/cli/pkg/storage"
2930)
3031
32+ // saveResetTestState captures and restores all package-level vars that the
33+ // apple-container reset tests override, reducing repetitive save/restore
34+ // boilerplate in individual test cases.
35+ func saveResetTestState (t * testing.T ) {
36+ t .Helper ()
37+ orig := struct {
38+ runtime string
39+ apiEnabled bool
40+ assertRunning func () error
41+ removeContainer func (context.Context , string , bool , bool ) error
42+ removeVolume func (context.Context , string , bool ) error
43+ startContainer func (context.Context , container.Config , container.HostConfig , network.NetworkingConfig , string ) (string , error )
44+ inspectContainer func (context.Context , string ) (utils.ContainerInfo , error )
45+ restartContainer func (context.Context , string ) error
46+ waitForHealthy func (context.Context , time.Duration , ... string ) error
47+ waitForLocalDB func (context.Context , time.Duration , ... func (* pgx.ConnConfig )) error
48+ waitForLocalAPI func (context.Context , time.Duration ) error
49+ setupLocalDB func (context.Context , string , afero.Fs , io.Writer , ... func (* pgx.ConnConfig )) error
50+ restartKongFn func (context.Context , start.KongDependencies ) error
51+ runBucketSeedFn func (context.Context , string , bool , afero.Fs ) error
52+ seedBucketsFn func (context.Context , afero.Fs ) error
53+ dbId , storageId string
54+ gotrueId , realtimeId string
55+ poolerId , kongId string
56+ }{
57+ runtime : string (utils .Config .Local .Runtime ),
58+ apiEnabled : utils .Config .Api .Enabled ,
59+ assertRunning : assertSupabaseDbIsRunning ,
60+ removeContainer : removeContainer ,
61+ removeVolume : removeVolume ,
62+ startContainer : startContainer ,
63+ inspectContainer : inspectContainer ,
64+ restartContainer : restartContainer ,
65+ waitForHealthy : waitForHealthyService ,
66+ waitForLocalDB : waitForLocalDatabase ,
67+ waitForLocalAPI : waitForLocalAPI ,
68+ setupLocalDB : setupLocalDatabase ,
69+ restartKongFn : restartKong ,
70+ runBucketSeedFn : runBucketSeed ,
71+ seedBucketsFn : seedBuckets ,
72+ dbId : utils .DbId ,
73+ storageId : utils .StorageId ,
74+ gotrueId : utils .GotrueId ,
75+ realtimeId : utils .RealtimeId ,
76+ poolerId : utils .PoolerId ,
77+ kongId : utils .KongId ,
78+ }
79+ t .Cleanup (func () {
80+ utils .Config .Local .Runtime = config .LocalRuntime (orig .runtime )
81+ utils .Config .Api .Enabled = orig .apiEnabled
82+ assertSupabaseDbIsRunning = orig .assertRunning
83+ removeContainer = orig .removeContainer
84+ removeVolume = orig .removeVolume
85+ startContainer = orig .startContainer
86+ inspectContainer = orig .inspectContainer
87+ restartContainer = orig .restartContainer
88+ waitForHealthyService = orig .waitForHealthy
89+ waitForLocalDatabase = orig .waitForLocalDB
90+ waitForLocalAPI = orig .waitForLocalAPI
91+ setupLocalDatabase = orig .setupLocalDB
92+ restartKong = orig .restartKongFn
93+ runBucketSeed = orig .runBucketSeedFn
94+ seedBuckets = orig .seedBucketsFn
95+ utils .DbId = orig .dbId
96+ utils .StorageId = orig .storageId
97+ utils .GotrueId = orig .gotrueId
98+ utils .RealtimeId = orig .realtimeId
99+ utils .PoolerId = orig .poolerId
100+ utils .KongId = orig .kongId
101+ })
102+ }
103+
31104func TestResetCommand (t * testing.T ) {
32105 utils .Config .Hostname = "127.0.0.1"
33106 utils .Config .Db .Port = 5432
@@ -170,49 +243,7 @@ func TestResetCommand(t *testing.T) {
170243 })
171244
172245 t .Run ("uses runtime helpers on apple container runtime" , func (t * testing.T ) {
173- originalRuntime := utils .Config .Local .Runtime
174- originalAPIEnabled := utils .Config .Api .Enabled
175- originalAssertRunning := assertSupabaseDbIsRunning
176- originalRemoveContainer := removeContainer
177- originalRemoveVolume := removeVolume
178- originalStartContainer := startContainer
179- originalInspectContainer := inspectContainer
180- originalRestartContainer := restartContainer
181- originalWaitForHealthyService := waitForHealthyService
182- originalWaitForLocalDatabase := waitForLocalDatabase
183- originalWaitForLocalAPI := waitForLocalAPI
184- originalSetupLocalDatabase := setupLocalDatabase
185- originalRestartKong := restartKong
186- originalRunBucketSeed := runBucketSeed
187- originalDbID := utils .DbId
188- originalStorageID := utils .StorageId
189- originalGotrueID := utils .GotrueId
190- originalRealtimeID := utils .RealtimeId
191- originalPoolerID := utils .PoolerId
192- originalKongID := utils .KongId
193-
194- t .Cleanup (func () {
195- utils .Config .Local .Runtime = originalRuntime
196- utils .Config .Api .Enabled = originalAPIEnabled
197- assertSupabaseDbIsRunning = originalAssertRunning
198- removeContainer = originalRemoveContainer
199- removeVolume = originalRemoveVolume
200- startContainer = originalStartContainer
201- inspectContainer = originalInspectContainer
202- restartContainer = originalRestartContainer
203- waitForHealthyService = originalWaitForHealthyService
204- waitForLocalDatabase = originalWaitForLocalDatabase
205- waitForLocalAPI = originalWaitForLocalAPI
206- setupLocalDatabase = originalSetupLocalDatabase
207- restartKong = originalRestartKong
208- runBucketSeed = originalRunBucketSeed
209- utils .DbId = originalDbID
210- utils .StorageId = originalStorageID
211- utils .GotrueId = originalGotrueID
212- utils .RealtimeId = originalRealtimeID
213- utils .PoolerId = originalPoolerID
214- utils .KongId = originalKongID
215- })
246+ saveResetTestState (t )
216247
217248 utils .Config .Local .Runtime = "apple-container"
218249 utils .Config .Db .MajorVersion = 15
0 commit comments