@@ -14,12 +14,14 @@ import (
14
14
"github.com/stretchr/testify/require"
15
15
"github.com/supabase/cli/internal/testing/apitest"
16
16
"github.com/supabase/cli/internal/utils"
17
+ "github.com/supabase/cli/internal/utils/flags"
17
18
"github.com/supabase/cli/pkg/api"
18
19
"github.com/supabase/cli/pkg/cast"
19
20
"github.com/supabase/cli/pkg/config"
20
21
)
21
22
22
23
func TestDeployCommand (t * testing.T ) {
24
+ flags .ProjectRef = apitest .RandomProjectRef ()
23
25
const slug = "test-func"
24
26
const containerId = "test-container"
25
27
imageUrl := utils .GetRegistryImageUrl (utils .Config .EdgeRuntime .Image )
@@ -29,8 +31,6 @@ func TestDeployCommand(t *testing.T) {
29
31
// Setup in-memory fs
30
32
fsys := afero .NewMemMapFs ()
31
33
require .NoError (t , utils .WriteConfig (fsys , false ))
32
- // Setup valid project ref
33
- project := apitest .RandomProjectRef ()
34
34
// Setup valid access token
35
35
token := apitest .RandomAccessToken (t )
36
36
t .Setenv ("SUPABASE_ACCESS_TOKEN" , string (token ))
@@ -40,13 +40,13 @@ func TestDeployCommand(t *testing.T) {
40
40
// Setup mock api
41
41
defer gock .OffAll ()
42
42
gock .New (utils .DefaultApiHost ).
43
- Get ("/v1/projects/" + project + "/functions" ).
43
+ Get ("/v1/projects/" + flags . ProjectRef + "/functions" ).
44
44
Reply (http .StatusOK ).
45
45
JSON ([]api.FunctionResponse {})
46
46
for i := range functions {
47
47
// Do not match slug to avoid flakey tests
48
48
gock .New (utils .DefaultApiHost ).
49
- Post ("/v1/projects/" + project + "/functions" ).
49
+ Post ("/v1/projects/" + flags . ProjectRef + "/functions" ).
50
50
Reply (http .StatusCreated ).
51
51
JSON (api.FunctionResponse {Id : fmt .Sprintf ("%d" , i )})
52
52
// Setup mock docker
@@ -61,7 +61,7 @@ func TestDeployCommand(t *testing.T) {
61
61
}
62
62
// Run test
63
63
noVerifyJWT := true
64
- err = Run (context .Background (), functions , project , & noVerifyJWT , "" , fsys )
64
+ err = Run (context .Background (), functions , true , & noVerifyJWT , "" , fsys )
65
65
// Check error
66
66
assert .NoError (t , err )
67
67
assert .Empty (t , apitest .ListUnmatchedRequests ())
@@ -88,8 +88,6 @@ import_map = "./import_map.json"
88
88
require .NoError (t , afero .WriteFile (fsys , entrypointPath , []byte {}, 0644 ))
89
89
ignorePath := filepath .Join (utils .FunctionsDir , "_ignore" , "index.ts" )
90
90
require .NoError (t , afero .WriteFile (fsys , ignorePath , []byte {}, 0644 ))
91
- // Setup valid project ref
92
- project := apitest .RandomProjectRef ()
93
91
// Setup valid access token
94
92
token := apitest .RandomAccessToken (t )
95
93
t .Setenv ("SUPABASE_ACCESS_TOKEN" , string (token ))
@@ -99,11 +97,11 @@ import_map = "./import_map.json"
99
97
// Setup mock api
100
98
defer gock .OffAll ()
101
99
gock .New (utils .DefaultApiHost ).
102
- Get ("/v1/projects/" + project + "/functions" ).
100
+ Get ("/v1/projects/" + flags . ProjectRef + "/functions" ).
103
101
Reply (http .StatusOK ).
104
102
JSON ([]api.FunctionResponse {})
105
103
gock .New (utils .DefaultApiHost ).
106
- Post ("/v1/projects/" + project + "/functions" ).
104
+ Post ("/v1/projects/" + flags . ProjectRef + "/functions" ).
107
105
MatchParam ("slug" , slug ).
108
106
ParamPresent ("import_map_path" ).
109
107
Reply (http .StatusCreated ).
@@ -116,7 +114,7 @@ import_map = "./import_map.json"
116
114
outputDir := filepath .Join (utils .TempDir , fmt .Sprintf (".output_%s" , slug ))
117
115
require .NoError (t , afero .WriteFile (fsys , filepath .Join (outputDir , "output.eszip" ), []byte ("" ), 0644 ))
118
116
// Run test
119
- err = Run (context .Background (), nil , project , nil , "" , fsys )
117
+ err = Run (context .Background (), nil , true , nil , "" , fsys )
120
118
// Check error
121
119
assert .NoError (t , err )
122
120
assert .Empty (t , apitest .ListUnmatchedRequests ())
@@ -142,8 +140,6 @@ import_map = "./import_map.json"
142
140
// Setup function entrypoints
143
141
require .NoError (t , afero .WriteFile (fsys , filepath .Join (utils .FunctionsDir , "enabled-func" , "index.ts" ), []byte {}, 0644 ))
144
142
require .NoError (t , afero .WriteFile (fsys , filepath .Join (utils .FunctionsDir , "disabled-func" , "index.ts" ), []byte {}, 0644 ))
145
- // Setup valid project ref
146
- project := apitest .RandomProjectRef ()
147
143
// Setup valid access token
148
144
token := apitest .RandomAccessToken (t )
149
145
t .Setenv ("SUPABASE_ACCESS_TOKEN" , string (token ))
@@ -153,11 +149,11 @@ import_map = "./import_map.json"
153
149
// Setup mock api
154
150
defer gock .OffAll ()
155
151
gock .New (utils .DefaultApiHost ).
156
- Get ("/v1/projects/" + project + "/functions" ).
152
+ Get ("/v1/projects/" + flags . ProjectRef + "/functions" ).
157
153
Reply (http .StatusOK ).
158
154
JSON ([]api.FunctionResponse {})
159
155
gock .New (utils .DefaultApiHost ).
160
- Post ("/v1/projects/" + project + "/functions" ).
156
+ Post ("/v1/projects/" + flags . ProjectRef + "/functions" ).
161
157
MatchParam ("slug" , "enabled-func" ).
162
158
Reply (http .StatusCreated ).
163
159
JSON (api.FunctionResponse {Id : "1" })
@@ -168,7 +164,7 @@ import_map = "./import_map.json"
168
164
outputDir := filepath .Join (utils .TempDir , ".output_enabled-func" )
169
165
require .NoError (t , afero .WriteFile (fsys , filepath .Join (outputDir , "output.eszip" ), []byte ("" ), 0644 ))
170
166
// Run test
171
- err = Run (context .Background (), nil , project , nil , "" , fsys )
167
+ err = Run (context .Background (), nil , true , nil , "" , fsys )
172
168
// Check error
173
169
assert .NoError (t , err )
174
170
assert .Empty (t , apitest .ListUnmatchedRequests ())
@@ -179,7 +175,7 @@ import_map = "./import_map.json"
179
175
fsys := afero .NewMemMapFs ()
180
176
require .NoError (t , utils .WriteConfig (fsys , false ))
181
177
// Run test
182
- err := Run (context .Background (), []string {"_invalid" }, "" , nil , "" , fsys )
178
+ err := Run (context .Background (), []string {"_invalid" }, true , nil , "" , fsys )
183
179
// Check error
184
180
assert .ErrorContains (t , err , "Invalid Function name." )
185
181
})
@@ -189,7 +185,7 @@ import_map = "./import_map.json"
189
185
fsys := afero .NewMemMapFs ()
190
186
require .NoError (t , utils .WriteConfig (fsys , false ))
191
187
// Run test
192
- err := Run (context .Background (), nil , "" , nil , "" , fsys )
188
+ err := Run (context .Background (), nil , true , nil , "" , fsys )
193
189
// Check error
194
190
assert .ErrorContains (t , err , "No Functions specified or found in supabase/functions" )
195
191
})
@@ -207,8 +203,6 @@ verify_jwt = false
207
203
` )
208
204
require .NoError (t , err )
209
205
require .NoError (t , f .Close ())
210
- // Setup valid project ref
211
- project := apitest .RandomProjectRef ()
212
206
// Setup valid access token
213
207
token := apitest .RandomAccessToken (t )
214
208
t .Setenv ("SUPABASE_ACCESS_TOKEN" , string (token ))
@@ -218,11 +212,11 @@ verify_jwt = false
218
212
// Setup mock api
219
213
defer gock .OffAll ()
220
214
gock .New (utils .DefaultApiHost ).
221
- Get ("/v1/projects/" + project + "/functions" ).
215
+ Get ("/v1/projects/" + flags . ProjectRef + "/functions" ).
222
216
Reply (http .StatusOK ).
223
217
JSON ([]api.FunctionResponse {})
224
218
gock .New (utils .DefaultApiHost ).
225
- Post ("/v1/projects/" + project + "/functions" ).
219
+ Post ("/v1/projects/" + flags . ProjectRef + "/functions" ).
226
220
MatchParam ("verify_jwt" , "false" ).
227
221
Reply (http .StatusCreated ).
228
222
JSON (api.FunctionResponse {Id : "1" })
@@ -234,7 +228,7 @@ verify_jwt = false
234
228
outputDir := filepath .Join (utils .TempDir , fmt .Sprintf (".output_%s" , slug ))
235
229
require .NoError (t , afero .WriteFile (fsys , filepath .Join (outputDir , "output.eszip" ), []byte ("" ), 0644 ))
236
230
// Run test
237
- assert .NoError (t , Run (context .Background (), []string {slug }, project , nil , "" , fsys ))
231
+ assert .NoError (t , Run (context .Background (), []string {slug }, true , nil , "" , fsys ))
238
232
// Validate api
239
233
assert .Empty (t , apitest .ListUnmatchedRequests ())
240
234
})
@@ -252,8 +246,6 @@ verify_jwt = false
252
246
` )
253
247
require .NoError (t , err )
254
248
require .NoError (t , f .Close ())
255
- // Setup valid project ref
256
- project := apitest .RandomProjectRef ()
257
249
// Setup valid access token
258
250
token := apitest .RandomAccessToken (t )
259
251
t .Setenv ("SUPABASE_ACCESS_TOKEN" , string (token ))
@@ -263,11 +255,11 @@ verify_jwt = false
263
255
// Setup mock api
264
256
defer gock .OffAll ()
265
257
gock .New (utils .DefaultApiHost ).
266
- Get ("/v1/projects/" + project + "/functions" ).
258
+ Get ("/v1/projects/" + flags . ProjectRef + "/functions" ).
267
259
Reply (http .StatusOK ).
268
260
JSON ([]api.FunctionResponse {})
269
261
gock .New (utils .DefaultApiHost ).
270
- Post ("/v1/projects/" + project + "/functions" ).
262
+ Post ("/v1/projects/" + flags . ProjectRef + "/functions" ).
271
263
MatchParam ("verify_jwt" , "true" ).
272
264
Reply (http .StatusCreated ).
273
265
JSON (api.FunctionResponse {Id : "1" })
@@ -280,7 +272,7 @@ verify_jwt = false
280
272
require .NoError (t , afero .WriteFile (fsys , filepath .Join (outputDir , "output.eszip" ), []byte ("" ), 0644 ))
281
273
// Run test
282
274
noVerifyJwt := false
283
- assert .NoError (t , Run (context .Background (), []string {slug }, project , & noVerifyJwt , "" , fsys ))
275
+ assert .NoError (t , Run (context .Background (), []string {slug }, true , & noVerifyJwt , "" , fsys ))
284
276
// Validate api
285
277
assert .Empty (t , apitest .ListUnmatchedRequests ())
286
278
})
0 commit comments