Skip to content

Commit a99c56c

Browse files
committed
chore: fix unit tests
1 parent da19bb0 commit a99c56c

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

internal/gen/types/typescript/typescript.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
"github.com/supabase/cli/pkg/api"
1717
)
1818

19-
func Run(ctx context.Context, projectId string, dbConfig pgconn.Config, schemas []string, postgrestV9Compat bool, fsys afero.Fs) error {
19+
func Run(ctx context.Context, projectId string, dbConfig pgconn.Config, schemas []string, postgrestV9Compat bool, fsys afero.Fs, options ...func(*pgx.ConnConfig)) error {
2020
// Add default schemas if --schema flag is not specified
2121
if len(schemas) == 0 {
2222
schemas = utils.RemoveDuplicates(append([]string{"public"}, utils.Config.Api.Schemas...))
@@ -54,7 +54,7 @@ func Run(ctx context.Context, projectId string, dbConfig pgconn.Config, schemas
5454
dbConfig.Database = "postgres"
5555
}
5656
escaped := utils.ToPostgresURL(dbConfig)
57-
if require, err := isRequireSSL(ctx, escaped); err != nil {
57+
if require, err := isRequireSSL(ctx, escaped, options...); err != nil {
5858
return err
5959
} else if require {
6060
// node-postgres does not support sslmode=prefer
@@ -84,13 +84,12 @@ func Run(ctx context.Context, projectId string, dbConfig pgconn.Config, schemas
8484
}
8585

8686
func isRequireSSL(ctx context.Context, dbUrl string, options ...func(*pgx.ConnConfig)) (bool, error) {
87-
conn, err := utils.ConnectByUrl(ctx, dbUrl+"&sslmode=require")
87+
conn, err := utils.ConnectByUrl(ctx, dbUrl+"&sslmode=require", options...)
8888
if err != nil {
8989
if strings.HasSuffix(err.Error(), "(server refused TLS connection)") {
9090
return false, nil
9191
}
9292
return false, err
9393
}
94-
defer conn.Close(context.Background())
95-
return true, nil
94+
return true, conn.Close(ctx)
9695
}

internal/gen/types/typescript/typescript_test.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/stretchr/testify/assert"
1313
"github.com/stretchr/testify/require"
1414
"github.com/supabase/cli/internal/testing/apitest"
15+
"github.com/supabase/cli/internal/testing/pgtest"
1516
"github.com/supabase/cli/internal/utils"
1617
"github.com/supabase/cli/pkg/api"
1718
"gopkg.in/h2non/gock.v1"
@@ -43,8 +44,11 @@ func TestGenLocalCommand(t *testing.T) {
4344
JSON(types.ContainerJSON{})
4445
apitest.MockDockerStart(utils.Docker, imageUrl, containerId)
4546
require.NoError(t, apitest.MockDockerLogs(utils.Docker, containerId, "hello world"))
47+
// Setup mock postgres
48+
conn := pgtest.NewConn()
49+
defer conn.Close(t)
4650
// Run test
47-
assert.NoError(t, Run(context.Background(), "", dbConfig, []string{}, true, fsys))
51+
assert.NoError(t, Run(context.Background(), "", dbConfig, []string{}, true, fsys, conn.Intercept))
4852
// Validate api
4953
assert.Empty(t, apitest.ListUnmatchedRequests())
5054
})
@@ -153,8 +157,11 @@ func TestGenRemoteCommand(t *testing.T) {
153157
defer gock.OffAll()
154158
apitest.MockDockerStart(utils.Docker, imageUrl, containerId)
155159
require.NoError(t, apitest.MockDockerLogs(utils.Docker, containerId, "hello world"))
160+
// Setup mock postgres
161+
conn := pgtest.NewConn()
162+
defer conn.Close(t)
156163
// Run test
157-
assert.NoError(t, Run(context.Background(), "", dbConfig, []string{"public"}, true, afero.NewMemMapFs()))
164+
assert.NoError(t, Run(context.Background(), "", dbConfig, []string{"public"}, true, afero.NewMemMapFs(), conn.Intercept))
158165
// Validate api
159166
assert.Empty(t, apitest.ListUnmatchedRequests())
160167
})

0 commit comments

Comments
 (0)