Skip to content

Commit aaa0d7f

Browse files
authored
chore: refactor use cast ptr (#2793)
* go mod tidy * chore: refactor use cast.Ptr
1 parent 3148eba commit aaa0d7f

File tree

15 files changed

+46
-37
lines changed

15 files changed

+46
-37
lines changed

cmd/functions.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/supabase/cli/internal/functions/serve"
1414
"github.com/supabase/cli/internal/utils"
1515
"github.com/supabase/cli/internal/utils/flags"
16+
"github.com/supabase/cli/pkg/cast"
1617
)
1718

1819
var (
@@ -106,9 +107,9 @@ var (
106107
}
107108

108109
if len(inspectMode.Value) > 0 {
109-
runtimeOption.InspectMode = utils.Ptr(serve.InspectMode(inspectMode.Value))
110+
runtimeOption.InspectMode = cast.Ptr(serve.InspectMode(inspectMode.Value))
110111
} else if inspectBrk {
111-
runtimeOption.InspectMode = utils.Ptr(serve.InspectModeBrk)
112+
runtimeOption.InspectMode = cast.Ptr(serve.InspectModeBrk)
112113
}
113114
if runtimeOption.InspectMode == nil && runtimeOption.InspectMain {
114115
return fmt.Errorf("--inspect-main must be used together with one of these flags: [inspect inspect-mode]")

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ require (
2525
github.com/go-xmlfmt/xmlfmt v1.1.2
2626
github.com/golang-jwt/jwt/v5 v5.2.1
2727
github.com/golangci/golangci-lint v1.61.0
28+
github.com/google/go-cmp v0.6.0
2829
github.com/google/go-github/v62 v62.0.0
2930
github.com/google/go-querystring v1.1.0
3031
github.com/google/uuid v1.6.0
@@ -169,7 +170,6 @@ require (
169170
github.com/golangci/plugin-module-register v0.1.1 // indirect
170171
github.com/golangci/revgrep v0.5.3 // indirect
171172
github.com/golangci/unconvert v0.0.0-20240309020433-c5143eacb3ed // indirect
172-
github.com/google/go-cmp v0.6.0 // indirect
173173
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
174174
github.com/gordonklaus/ineffassign v0.1.0 // indirect
175175
github.com/gorilla/css v1.0.0 // indirect

internal/branches/create/create_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/supabase/cli/internal/utils"
1515
"github.com/supabase/cli/internal/utils/flags"
1616
"github.com/supabase/cli/pkg/api"
17+
"github.com/supabase/cli/pkg/cast"
1718
)
1819

1920
func TestCreateCommand(t *testing.T) {
@@ -36,7 +37,7 @@ func TestCreateCommand(t *testing.T) {
3637
})
3738
// Run test
3839
err := Run(context.Background(), api.CreateBranchBody{
39-
Region: utils.Ptr("sin"),
40+
Region: cast.Ptr("sin"),
4041
}, fsys)
4142
// Check error
4243
assert.NoError(t, err)
@@ -53,7 +54,7 @@ func TestCreateCommand(t *testing.T) {
5354
ReplyError(net.ErrClosed)
5455
// Run test
5556
err := Run(context.Background(), api.CreateBranchBody{
56-
Region: utils.Ptr("sin"),
57+
Region: cast.Ptr("sin"),
5758
}, fsys)
5859
// Check error
5960
assert.ErrorIs(t, err, net.ErrClosed)
@@ -70,7 +71,7 @@ func TestCreateCommand(t *testing.T) {
7071
Reply(http.StatusServiceUnavailable)
7172
// Run test
7273
err := Run(context.Background(), api.CreateBranchBody{
73-
Region: utils.Ptr("sin"),
74+
Region: cast.Ptr("sin"),
7475
}, fsys)
7576
// Check error
7677
assert.ErrorContains(t, err, "Unexpected error creating preview branch:")

internal/functions/deploy/deploy.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/go-errors/errors"
1111
"github.com/spf13/afero"
1212
"github.com/supabase/cli/internal/utils"
13+
"github.com/supabase/cli/pkg/cast"
1314
"github.com/supabase/cli/pkg/config"
1415
"github.com/supabase/cli/pkg/function"
1516
)
@@ -86,7 +87,7 @@ func GetFunctionConfig(slugs []string, importMapPath string, noVerifyJWT *bool,
8687
function.ImportMap = utils.FallbackImportMapPath
8788
}
8889
if noVerifyJWT != nil {
89-
function.VerifyJWT = utils.Ptr(!*noVerifyJWT)
90+
function.VerifyJWT = cast.Ptr(!*noVerifyJWT)
9091
}
9192
functionConfig[name] = function
9293
}

internal/functions/deploy/deploy_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/supabase/cli/internal/testing/apitest"
1616
"github.com/supabase/cli/internal/utils"
1717
"github.com/supabase/cli/pkg/api"
18+
"github.com/supabase/cli/pkg/cast"
1819
"github.com/supabase/cli/pkg/config"
1920
)
2021

@@ -323,7 +324,7 @@ func TestImportMapPath(t *testing.T) {
323324
fsys := afero.NewMemMapFs()
324325
require.NoError(t, afero.WriteFile(fsys, utils.FallbackImportMapPath, []byte("{}"), 0644))
325326
// Run test
326-
fc, err := GetFunctionConfig([]string{slug}, utils.FallbackImportMapPath, utils.Ptr(false), fsys)
327+
fc, err := GetFunctionConfig([]string{slug}, utils.FallbackImportMapPath, cast.Ptr(false), fsys)
327328
// Check error
328329
assert.NoError(t, err)
329330
assert.Equal(t, utils.FallbackImportMapPath, fc[slug].ImportMap)

internal/functions/serve/serve_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/stretchr/testify/require"
1515
"github.com/supabase/cli/internal/testing/apitest"
1616
"github.com/supabase/cli/internal/utils"
17+
"github.com/supabase/cli/pkg/cast"
1718
)
1819

1920
func TestServeCommand(t *testing.T) {
@@ -100,7 +101,7 @@ func TestServeCommand(t *testing.T) {
100101
Reply(http.StatusOK).
101102
JSON(types.ContainerJSON{})
102103
// Run test
103-
err := Run(context.Background(), ".env", utils.Ptr(true), "import_map.json", RuntimeOption{}, fsys)
104+
err := Run(context.Background(), ".env", cast.Ptr(true), "import_map.json", RuntimeOption{}, fsys)
104105
// Check error
105106
assert.ErrorIs(t, err, os.ErrNotExist)
106107
})

internal/init/init_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/stretchr/testify/require"
1212
"github.com/supabase/cli/internal/testing/fstest"
1313
"github.com/supabase/cli/internal/utils"
14+
"github.com/supabase/cli/pkg/cast"
1415
)
1516

1617
func TestInitCommand(t *testing.T) {
@@ -70,7 +71,7 @@ func TestInitCommand(t *testing.T) {
7071
// Setup in-memory fs
7172
fsys := &afero.MemMapFs{}
7273
// Run test
73-
assert.NoError(t, Run(context.Background(), fsys, utils.Ptr(true), nil, utils.InitParams{}))
74+
assert.NoError(t, Run(context.Background(), fsys, cast.Ptr(true), nil, utils.InitParams{}))
7475
// Validate generated vscode settings
7576
exists, err := afero.Exists(fsys, settingsPath)
7677
assert.NoError(t, err)
@@ -84,7 +85,7 @@ func TestInitCommand(t *testing.T) {
8485
// Setup in-memory fs
8586
fsys := &afero.MemMapFs{}
8687
// Run test
87-
assert.NoError(t, Run(context.Background(), fsys, utils.Ptr(false), nil, utils.InitParams{}))
88+
assert.NoError(t, Run(context.Background(), fsys, cast.Ptr(false), nil, utils.InitParams{}))
8889
// Validate vscode settings file isn't generated
8990
exists, err := afero.Exists(fsys, settingsPath)
9091
assert.NoError(t, err)
@@ -98,7 +99,7 @@ func TestInitCommand(t *testing.T) {
9899
// Setup in-memory fs
99100
fsys := &afero.MemMapFs{}
100101
// Run test
101-
assert.NoError(t, Run(context.Background(), fsys, nil, utils.Ptr(true), utils.InitParams{}))
102+
assert.NoError(t, Run(context.Background(), fsys, nil, cast.Ptr(true), utils.InitParams{}))
102103
// Validate generated intellij deno config
103104
exists, err := afero.Exists(fsys, denoPath)
104105
assert.NoError(t, err)
@@ -109,7 +110,7 @@ func TestInitCommand(t *testing.T) {
109110
// Setup in-memory fs
110111
fsys := &afero.MemMapFs{}
111112
// Run test
112-
assert.NoError(t, Run(context.Background(), fsys, nil, utils.Ptr(false), utils.InitParams{}))
113+
assert.NoError(t, Run(context.Background(), fsys, nil, cast.Ptr(false), utils.InitParams{}))
113114
// Validate intellij deno config file isn't generated
114115
exists, err := afero.Exists(fsys, denoPath)
115116
assert.NoError(t, err)

internal/storage/cp/cp_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,17 @@ import (
1414
"github.com/supabase/cli/internal/utils"
1515
"github.com/supabase/cli/internal/utils/flags"
1616
"github.com/supabase/cli/pkg/api"
17+
"github.com/supabase/cli/pkg/cast"
1718
"github.com/supabase/cli/pkg/fetcher"
1819
"github.com/supabase/cli/pkg/storage"
1920
)
2021

2122
var mockFile = storage.ObjectResponse{
2223
Name: "abstract.pdf",
23-
Id: utils.Ptr("9b7f9f48-17a6-4ca8-b14a-39b0205a63e9"),
24-
UpdatedAt: utils.Ptr("2023-10-13T18:08:22.068Z"),
25-
CreatedAt: utils.Ptr("2023-10-13T18:08:22.068Z"),
26-
LastAccessedAt: utils.Ptr("2023-10-13T18:08:22.068Z"),
24+
Id: cast.Ptr("9b7f9f48-17a6-4ca8-b14a-39b0205a63e9"),
25+
UpdatedAt: cast.Ptr("2023-10-13T18:08:22.068Z"),
26+
CreatedAt: cast.Ptr("2023-10-13T18:08:22.068Z"),
27+
LastAccessedAt: cast.Ptr("2023-10-13T18:08:22.068Z"),
2728
Metadata: &storage.ObjectMetadata{
2829
ETag: `"887ea9be3c68e6f2fca7fd2d7c77d8fe"`,
2930
Size: 82702,

internal/storage/ls/ls_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,17 @@ import (
1414
"github.com/supabase/cli/internal/utils"
1515
"github.com/supabase/cli/internal/utils/flags"
1616
"github.com/supabase/cli/pkg/api"
17+
"github.com/supabase/cli/pkg/cast"
1718
"github.com/supabase/cli/pkg/fetcher"
1819
"github.com/supabase/cli/pkg/storage"
1920
)
2021

2122
var mockFile = storage.ObjectResponse{
2223
Name: "abstract.pdf",
23-
Id: utils.Ptr("9b7f9f48-17a6-4ca8-b14a-39b0205a63e9"),
24-
UpdatedAt: utils.Ptr("2023-10-13T18:08:22.068Z"),
25-
CreatedAt: utils.Ptr("2023-10-13T18:08:22.068Z"),
26-
LastAccessedAt: utils.Ptr("2023-10-13T18:08:22.068Z"),
24+
Id: cast.Ptr("9b7f9f48-17a6-4ca8-b14a-39b0205a63e9"),
25+
UpdatedAt: cast.Ptr("2023-10-13T18:08:22.068Z"),
26+
CreatedAt: cast.Ptr("2023-10-13T18:08:22.068Z"),
27+
LastAccessedAt: cast.Ptr("2023-10-13T18:08:22.068Z"),
2728
Metadata: &storage.ObjectMetadata{
2829
ETag: `"887ea9be3c68e6f2fca7fd2d7c77d8fe"`,
2930
Size: 82702,

internal/storage/mv/mv_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,17 @@ import (
1212
"github.com/supabase/cli/internal/utils"
1313
"github.com/supabase/cli/internal/utils/flags"
1414
"github.com/supabase/cli/pkg/api"
15+
"github.com/supabase/cli/pkg/cast"
1516
"github.com/supabase/cli/pkg/fetcher"
1617
"github.com/supabase/cli/pkg/storage"
1718
)
1819

1920
var mockFile = storage.ObjectResponse{
2021
Name: "abstract.pdf",
21-
Id: utils.Ptr("9b7f9f48-17a6-4ca8-b14a-39b0205a63e9"),
22-
UpdatedAt: utils.Ptr("2023-10-13T18:08:22.068Z"),
23-
CreatedAt: utils.Ptr("2023-10-13T18:08:22.068Z"),
24-
LastAccessedAt: utils.Ptr("2023-10-13T18:08:22.068Z"),
22+
Id: cast.Ptr("9b7f9f48-17a6-4ca8-b14a-39b0205a63e9"),
23+
UpdatedAt: cast.Ptr("2023-10-13T18:08:22.068Z"),
24+
CreatedAt: cast.Ptr("2023-10-13T18:08:22.068Z"),
25+
LastAccessedAt: cast.Ptr("2023-10-13T18:08:22.068Z"),
2526
Metadata: &storage.ObjectMetadata{
2627
ETag: `"887ea9be3c68e6f2fca7fd2d7c77d8fe"`,
2728
Size: 82702,

0 commit comments

Comments
 (0)