Skip to content

Commit c4248c8

Browse files
authored
Merge branch 'develop' into fix/ir
2 parents d71d0dc + c7dc5cd commit c4248c8

37 files changed

Lines changed: 1336 additions & 291 deletions

File tree

api/overlay.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ actions:
3838
- target: $.components.schemas.*.properties.private_jwk.discriminator
3939
description: Replaces discriminated union with concrete type
4040
remove: true
41+
- target: $.components.schemas.DiskRequestBody.properties.attributes.discriminator
42+
description: Replaces discriminated union with concrete type
43+
remove: true
4144
- target: $.paths.*.*.parameters[?(@.name=='branch_id_or_ref')]
4245
update:
4346
schema:

cmd/branches.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616
"github.com/supabase/cli/internal/branches/pause"
1717
"github.com/supabase/cli/internal/branches/unpause"
1818
"github.com/supabase/cli/internal/branches/update"
19-
"github.com/supabase/cli/internal/gen/keys"
2019
"github.com/supabase/cli/internal/utils"
2120
"github.com/supabase/cli/internal/utils/flags"
2221
"github.com/supabase/cli/pkg/api"
@@ -229,7 +228,7 @@ func promptBranchId(ctx context.Context, fsys afero.Fs) error {
229228
if console := utils.NewConsole(); !console.IsTTY {
230229
// Only read from stdin if the terminal is non-interactive
231230
title := "Enter the name of your branch"
232-
if branchId = keys.GetGitBranch(fsys); len(branchId) > 0 {
231+
if branchId = utils.GetGitBranch(fsys); len(branchId) > 0 {
233232
title += fmt.Sprintf(" (or leave blank to use %s)", utils.Aqua(branchId))
234233
}
235234
title += ": "

cmd/db.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ import (
88
"github.com/spf13/afero"
99
"github.com/spf13/cobra"
1010
"github.com/spf13/viper"
11-
"github.com/supabase/cli/internal/db/branch/create"
12-
"github.com/supabase/cli/internal/db/branch/delete"
13-
"github.com/supabase/cli/internal/db/branch/list"
14-
"github.com/supabase/cli/internal/db/branch/switch_"
1511
"github.com/supabase/cli/internal/db/diff"
1612
"github.com/supabase/cli/internal/db/dump"
1713
"github.com/supabase/cli/internal/db/lint"
@@ -22,6 +18,11 @@ import (
2218
"github.com/supabase/cli/internal/db/test"
2319
"github.com/supabase/cli/internal/utils"
2420
"github.com/supabase/cli/internal/utils/flags"
21+
"github.com/supabase/cli/legacy/branch/create"
22+
"github.com/supabase/cli/legacy/branch/delete"
23+
"github.com/supabase/cli/legacy/branch/list"
24+
"github.com/supabase/cli/legacy/branch/switch_"
25+
legacy "github.com/supabase/cli/legacy/diff"
2526
"github.com/supabase/cli/pkg/migration"
2627
)
2728

@@ -90,7 +91,7 @@ var (
9091
Short: "Diffs the local database for schema changes",
9192
RunE: func(cmd *cobra.Command, args []string) error {
9293
if usePgAdmin {
93-
return diff.RunPgAdmin(cmd.Context(), schema, file, flags.DbConfig, afero.NewOsFs())
94+
return legacy.RunPgAdmin(cmd.Context(), schema, file, flags.DbConfig, afero.NewOsFs())
9495
}
9596
differ := diff.DiffSchemaMigra
9697
if usePgSchema {

cmd/encryption.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package cmd
22

33
import (
4-
"os"
5-
64
"github.com/spf13/cobra"
75
"github.com/supabase/cli/internal/encryption/get"
86
"github.com/supabase/cli/internal/encryption/update"
@@ -28,7 +26,7 @@ var (
2826
Use: "update-root-key",
2927
Short: "Update root encryption key of a Supabase project",
3028
RunE: func(cmd *cobra.Command, args []string) error {
31-
return update.Run(cmd.Context(), flags.ProjectRef, os.Stdin)
29+
return update.Run(cmd.Context(), flags.ProjectRef)
3230
},
3331
}
3432
)

cmd/gen.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ import (
1313
"github.com/spf13/afero"
1414
"github.com/spf13/cobra"
1515
"github.com/supabase/cli/internal/gen/bearerjwt"
16-
"github.com/supabase/cli/internal/gen/keys"
1716
"github.com/supabase/cli/internal/gen/signingkeys"
1817
"github.com/supabase/cli/internal/gen/types"
1918
"github.com/supabase/cli/internal/utils"
2019
"github.com/supabase/cli/internal/utils/flags"
20+
"github.com/supabase/cli/legacy/keys"
2121
"github.com/supabase/cli/pkg/config"
2222
)
2323

go.mod

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ require (
5454
github.com/withfig/autocomplete-tools/packages/cobra v1.2.0
5555
github.com/zalando/go-keyring v0.2.6
5656
go.opentelemetry.io/otel v1.40.0
57-
golang.org/x/mod v0.32.0
58-
golang.org/x/net v0.49.0
57+
golang.org/x/mod v0.33.0
58+
golang.org/x/net v0.50.0
5959
golang.org/x/oauth2 v0.35.0
60-
golang.org/x/term v0.39.0
61-
google.golang.org/grpc v1.78.0
60+
golang.org/x/term v0.40.0
61+
google.golang.org/grpc v1.79.1
6262
gopkg.in/yaml.v3 v3.0.1
6363
)
6464

@@ -427,13 +427,13 @@ require (
427427
go.uber.org/zap v1.27.0 // indirect
428428
go.yaml.in/yaml/v2 v2.4.3 // indirect
429429
go.yaml.in/yaml/v3 v3.0.4 // indirect
430-
golang.org/x/crypto v0.47.0 // indirect
430+
golang.org/x/crypto v0.48.0 // indirect
431431
golang.org/x/exp/typeparams v0.0.0-20250210185358-939b2ce775ac // indirect
432432
golang.org/x/sync v0.19.0 // indirect
433-
golang.org/x/sys v0.40.0 // indirect
434-
golang.org/x/text v0.33.0 // indirect
433+
golang.org/x/sys v0.41.0 // indirect
434+
golang.org/x/text v0.34.0 // indirect
435435
golang.org/x/time v0.11.0 // indirect
436-
golang.org/x/tools v0.40.0 // indirect
436+
golang.org/x/tools v0.41.0 // indirect
437437
golang.org/x/tools/go/expect v0.1.1-deprecated // indirect
438438
golang.org/x/tools/go/packages/packagestest v0.1.1-deprecated // indirect
439439
google.golang.org/genproto/googleapis/api v0.0.0-20251222181119-0a764e51fe1b // indirect

go.sum

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,8 +1233,8 @@ golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliY
12331233
golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
12341234
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
12351235
golang.org/x/crypto v0.20.0/go.mod h1:Xwo95rrVNIoSMx9wa1JroENMToLWn3RNVrTBpLHgZPQ=
1236-
golang.org/x/crypto v0.47.0 h1:V6e3FRj+n4dbpw86FJ8Fv7XVOql7TEwpHapKoMJ/GO8=
1237-
golang.org/x/crypto v0.47.0/go.mod h1:ff3Y9VzzKbwSSEzWqJsJVBnWmRwRSHt/6Op5n9bQc4A=
1236+
golang.org/x/crypto v0.48.0 h1:/VRzVqiRSggnhY7gNRxPauEQ5Drw9haKdM0jqfcCFts=
1237+
golang.org/x/crypto v0.48.0/go.mod h1:r0kV5h3qnFPlQnBSrULhlsRfryS2pmewsg+XfMgkVos=
12381238
golang.org/x/exp v0.0.0-20250911091902-df9299821621 h1:2id6c1/gto0kaHYyrixvknJ8tUK/Qs5IsmBtrc+FtgU=
12391239
golang.org/x/exp v0.0.0-20250911091902-df9299821621/go.mod h1:TwQYMMnGpvZyc+JpB/UAuTNIsVJifOlSkrZkhcvpVUk=
12401240
golang.org/x/exp/typeparams v0.0.0-20220428152302-39d4317da171/go.mod h1:AbB0pIl9nAr9wVwH+Z2ZpaocVmF5I4GyWCDIsVjR0bk=
@@ -1255,8 +1255,8 @@ golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
12551255
golang.org/x/mod v0.9.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
12561256
golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
12571257
golang.org/x/mod v0.13.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
1258-
golang.org/x/mod v0.32.0 h1:9F4d3PHLljb6x//jOyokMv3eX+YDeepZSEo3mFJy93c=
1259-
golang.org/x/mod v0.32.0/go.mod h1:SgipZ/3h2Ci89DlEtEXWUk/HteuRin+HHhN+WbNhguU=
1258+
golang.org/x/mod v0.33.0 h1:tHFzIWbBifEmbwtGz65eaWyGiGZatSrT9prnU8DbVL8=
1259+
golang.org/x/mod v0.33.0/go.mod h1:swjeQEj+6r7fODbD2cqrnje9PnziFuw4bmLbBZFrQ5w=
12601260
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
12611261
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
12621262
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
@@ -1282,8 +1282,8 @@ golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
12821282
golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk=
12831283
golang.org/x/net v0.16.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
12841284
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
1285-
golang.org/x/net v0.49.0 h1:eeHFmOGUTtaaPSGNmjBKpbng9MulQsJURQUAfUwY++o=
1286-
golang.org/x/net v0.49.0/go.mod h1:/ysNB2EvaqvesRkuLAyjI1ycPZlQHM3q01F02UY/MV8=
1285+
golang.org/x/net v0.50.0 h1:ucWh9eiCGyDR3vtzso0WMQinm2Dnt8cFMuQa9K33J60=
1286+
golang.org/x/net v0.50.0/go.mod h1:UgoSli3F/pBgdJBHCTc+tp3gmrU4XswgGRgtnwWTfyM=
12871287
golang.org/x/oauth2 v0.35.0 h1:Mv2mzuHuZuY2+bkyWXIHMfhNdJAdwW3FuWeCPYN5GVQ=
12881288
golang.org/x/oauth2 v0.35.0/go.mod h1:lzm5WQJQwKZ3nwavOZ3IS5Aulzxi68dUSgRHujetwEA=
12891289
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@@ -1344,8 +1344,8 @@ golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
13441344
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
13451345
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
13461346
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
1347-
golang.org/x/sys v0.40.0 h1:DBZZqJ2Rkml6QMQsZywtnjnnGvHza6BTfYFWY9kjEWQ=
1348-
golang.org/x/sys v0.40.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
1347+
golang.org/x/sys v0.41.0 h1:Ivj+2Cp/ylzLiEU89QhWblYnOE9zerudt9Ftecq2C6k=
1348+
golang.org/x/sys v0.41.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
13491349
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
13501350
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
13511351
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
@@ -1356,8 +1356,8 @@ golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
13561356
golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU=
13571357
golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U=
13581358
golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
1359-
golang.org/x/term v0.39.0 h1:RclSuaJf32jOqZz74CkPA9qFuVTX7vhLlpfj/IGWlqY=
1360-
golang.org/x/term v0.39.0/go.mod h1:yxzUCTP/U+FzoxfdKmLaA0RV1WgE0VY7hXBwKtY/4ww=
1359+
golang.org/x/term v0.40.0 h1:36e4zGLqU4yhjlmxEaagx2KuYbJq3EwY8K943ZsHcvg=
1360+
golang.org/x/term v0.40.0/go.mod h1:w2P8uVp06p2iyKKuvXIm7N/y0UCRt3UfJTfZ7oOpglM=
13611361
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
13621362
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
13631363
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
@@ -1370,8 +1370,8 @@ golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
13701370
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
13711371
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
13721372
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
1373-
golang.org/x/text v0.33.0 h1:B3njUFyqtHDUI5jMn1YIr5B0IE2U0qck04r6d4KPAxE=
1374-
golang.org/x/text v0.33.0/go.mod h1:LuMebE6+rBincTi9+xWTY8TztLzKHc/9C1uBCG27+q8=
1373+
golang.org/x/text v0.34.0 h1:oL/Qq0Kdaqxa1KbNeMKwQq0reLCCaFtqu2eNuSeNHbk=
1374+
golang.org/x/text v0.34.0/go.mod h1:homfLqTYRFyVYemLBFl5GgL/DWEiH5wcsQ5gSh1yziA=
13751375
golang.org/x/time v0.11.0 h1:/bpjEDfN9tkoN/ryeYHnv5hcMlc8ncjMcM4XBk5NWV0=
13761376
golang.org/x/time v0.11.0/go.mod h1:CDIdPxbZBQxdj6cxyCIdrNogrJKMJ7pr37NYpMcMDSg=
13771377
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
@@ -1402,8 +1402,8 @@ golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
14021402
golang.org/x/tools v0.7.0/go.mod h1:4pg6aUX35JBAogB10C9AtvVL+qowtN4pT3CGSQex14s=
14031403
golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58=
14041404
golang.org/x/tools v0.14.0/go.mod h1:uYBEerGOWcJyEORxN+Ek8+TT266gXkNlHdJBwexUsBg=
1405-
golang.org/x/tools v0.40.0 h1:yLkxfA+Qnul4cs9QA3KnlFu0lVmd8JJfoq+E41uSutA=
1406-
golang.org/x/tools v0.40.0/go.mod h1:Ik/tzLRlbscWpqqMRjyWYDisX8bG13FrdXp3o4Sr9lc=
1405+
golang.org/x/tools v0.41.0 h1:a9b8iMweWG+S0OBnlU36rzLp20z1Rp10w+IY2czHTQc=
1406+
golang.org/x/tools v0.41.0/go.mod h1:XSY6eDqxVNiYgezAVqqCeihT4j1U2CCsqvH3WhQpnlg=
14071407
golang.org/x/tools/go/expect v0.1.1-deprecated h1:jpBZDwmgPhXsKZC6WhL20P4b/wmnpsEAGHaNy0n/rJM=
14081408
golang.org/x/tools/go/expect v0.1.1-deprecated/go.mod h1:eihoPOH+FgIqa3FpoTwguz/bVUSGBlGQU67vpBeOrBY=
14091409
golang.org/x/tools/go/packages/packagestest v0.1.1-deprecated h1:1h2MnaIAIXISqTFKdENegdpAgUXz6NrPEsbIeWaBRvM=
@@ -1421,8 +1421,8 @@ google.golang.org/genproto/googleapis/api v0.0.0-20251222181119-0a764e51fe1b/go.
14211421
google.golang.org/genproto/googleapis/rpc v0.0.0-20251222181119-0a764e51fe1b h1:Mv8VFug0MP9e5vUxfBcE3vUkV6CImK3cMNMIDFjmzxU=
14221422
google.golang.org/genproto/googleapis/rpc v0.0.0-20251222181119-0a764e51fe1b/go.mod h1:j9x/tPzZkyxcgEFkiKEEGxfvyumM01BEtsW8xzOahRQ=
14231423
google.golang.org/grpc v1.0.5/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw=
1424-
google.golang.org/grpc v1.78.0 h1:K1XZG/yGDJnzMdd/uZHAkVqJE+xIDOcmdSFZkBUicNc=
1425-
google.golang.org/grpc v1.78.0/go.mod h1:I47qjTo4OKbMkjA/aOOwxDIiPSBofUtQUI5EfpWvW7U=
1424+
google.golang.org/grpc v1.79.1 h1:zGhSi45ODB9/p3VAawt9a+O/MULLl9dpizzNNpq7flY=
1425+
google.golang.org/grpc v1.79.1/go.mod h1:KmT0Kjez+0dde/v2j9vzwoAScgEPx/Bw1CYChhHLrHQ=
14261426
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
14271427
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
14281428
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=

internal/branches/create/create.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@ import (
88
"github.com/go-errors/errors"
99
"github.com/spf13/afero"
1010
"github.com/supabase/cli/internal/branches/list"
11-
"github.com/supabase/cli/internal/gen/keys"
1211
"github.com/supabase/cli/internal/utils"
1312
"github.com/supabase/cli/internal/utils/flags"
1413
"github.com/supabase/cli/pkg/api"
1514
)
1615

1716
func Run(ctx context.Context, body api.CreateBranchBody, fsys afero.Fs) error {
18-
gitBranch := keys.GetGitBranchOrDefault("", fsys)
17+
gitBranch := utils.GetGitBranchOrDefault("", fsys)
1918
if len(body.BranchName) == 0 && len(gitBranch) > 0 {
2019
title := fmt.Sprintf("Do you want to create a branch named %s?", utils.Aqua(gitBranch))
2120
if shouldCreate, err := utils.NewConsole().PromptYesNo(ctx, title, true); err != nil {

internal/config/push/push_test.go

Lines changed: 66 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,53 @@ import (
1111
"github.com/stretchr/testify/assert"
1212
"github.com/stretchr/testify/require"
1313
"github.com/supabase/cli/internal/testing/apitest"
14+
"github.com/supabase/cli/internal/testing/fstest"
1415
"github.com/supabase/cli/internal/utils"
16+
"github.com/supabase/cli/pkg/api"
1517
)
1618

1719
func TestPushConfig(t *testing.T) {
1820
project := apitest.RandomProjectRef()
19-
// Setup valid access token
20-
token := apitest.RandomAccessToken(t)
21-
t.Setenv("SUPABASE_ACCESS_TOKEN", string(token))
21+
22+
t.Run("pushes local config", func(t *testing.T) {
23+
errNetwork := errors.New("network error")
24+
t.Cleanup(fstest.MockStdin(t, "y"))
25+
t.Cleanup(apitest.MockPlatformAPI(t))
26+
// Setup in-memory fs
27+
fsys := afero.NewMemMapFs()
28+
// Setup mock api
29+
gock.New(utils.DefaultApiHost).
30+
Get("/v1/projects/"+project+"/billing/addons").
31+
Reply(http.StatusOK).
32+
SetHeader("Content-Type", "application/json").
33+
BodyString(`{
34+
"available_addons":[{
35+
"name": "GraphQL",
36+
"type": "api",
37+
"variants": [{
38+
"id": "api_graphql",
39+
"name": "GraphQL",
40+
"price": {
41+
"amount": 0.1027,
42+
"description": "$75/month, then $10/month",
43+
"interval": "hourly",
44+
"type": "usage"
45+
}
46+
}]
47+
}]
48+
}`)
49+
gock.New(utils.DefaultApiHost).
50+
Get("/v1/projects/" + project + "/postgrest").
51+
Reply(http.StatusOK).
52+
JSON(api.V1PostgrestConfigResponse{})
53+
gock.New(utils.DefaultApiHost).
54+
Patch("/v1/projects/" + project + "/postgrest").
55+
ReplyError(errNetwork)
56+
// Run test
57+
err := Run(context.Background(), project, fsys)
58+
// Check error
59+
assert.ErrorIs(t, err, errNetwork)
60+
})
2261

2362
t.Run("throws error on malformed config", func(t *testing.T) {
2463
// Setup in-memory fs
@@ -31,10 +70,10 @@ func TestPushConfig(t *testing.T) {
3170
})
3271

3372
t.Run("throws error on service unavailable", func(t *testing.T) {
73+
t.Cleanup(apitest.MockPlatformAPI(t))
3474
// Setup in-memory fs
3575
fsys := afero.NewMemMapFs()
3676
// Setup mock api
37-
defer gock.OffAll()
3877
gock.New(utils.DefaultApiHost).
3978
Get("/v1/projects/" + project + "/billing/addons").
4079
Reply(http.StatusServiceUnavailable)
@@ -47,13 +86,10 @@ func TestPushConfig(t *testing.T) {
4786

4887
func TestCostMatrix(t *testing.T) {
4988
project := apitest.RandomProjectRef()
50-
// Setup valid access token
51-
token := apitest.RandomAccessToken(t)
52-
t.Setenv("SUPABASE_ACCESS_TOKEN", string(token))
5389

5490
t.Run("fetches cost matrix", func(t *testing.T) {
91+
t.Cleanup(apitest.MockPlatformAPI(t))
5592
// Setup mock api
56-
defer gock.OffAll()
5793
gock.New(utils.DefaultApiHost).
5894
Get("/v1/projects/"+project+"/billing/addons").
5995
Reply(http.StatusOK).
@@ -66,10 +102,10 @@ func TestCostMatrix(t *testing.T) {
66102
"id": "auth_mfa_phone_default",
67103
"name": "Advanced MFA - Phone",
68104
"price": {
69-
"amount": 0.1027,
70-
"description": "$75/month, then $10/month",
71-
"interval": "hourly",
72-
"type": "usage"
105+
"amount": 0.1027,
106+
"description": "$75/month, then $10/month",
107+
"interval": "hourly",
108+
"type": "usage"
73109
}
74110
}]
75111
}, {
@@ -79,10 +115,10 @@ func TestCostMatrix(t *testing.T) {
79115
"id": "auth_mfa_web_authn_default",
80116
"name": "Advanced MFA - WebAuthn",
81117
"price": {
82-
"amount": 0.1027,
83-
"description": "$75/month, then $10/month",
84-
"interval": "hourly",
85-
"type": "usage"
118+
"amount": 0.1027,
119+
"description": "$75/month, then $10/month",
120+
"interval": "hourly",
121+
"type": "usage"
86122
}
87123
}]
88124
}]
@@ -100,8 +136,8 @@ func TestCostMatrix(t *testing.T) {
100136

101137
t.Run("throws error on network error", func(t *testing.T) {
102138
errNetwork := errors.New("network error")
139+
t.Cleanup(apitest.MockPlatformAPI(t))
103140
// Setup mock api
104-
defer gock.OffAll()
105141
gock.New(utils.DefaultApiHost).
106142
Get("/v1/projects/" + project + "/billing/addons").
107143
ReplyError(errNetwork)
@@ -111,4 +147,17 @@ func TestCostMatrix(t *testing.T) {
111147
assert.ErrorIs(t, err, errNetwork)
112148
assert.Nil(t, cost)
113149
})
150+
151+
t.Run("throws error on service unavailable", func(t *testing.T) {
152+
t.Cleanup(apitest.MockPlatformAPI(t))
153+
// Setup mock api
154+
gock.New(utils.DefaultApiHost).
155+
Get("/v1/projects/" + project + "/billing/addons").
156+
Reply(http.StatusServiceUnavailable)
157+
// Run test
158+
cost, err := getCostMatrix(context.Background(), project)
159+
// Check error
160+
assert.ErrorContains(t, err, "unexpected list addons status 503:")
161+
assert.Nil(t, cost)
162+
})
114163
}

0 commit comments

Comments
 (0)