Skip to content

Commit

Permalink
CLI Sync postgres integration test + refactor (#2854)
Browse files Browse the repository at this point in the history
  • Loading branch information
alishakawaguchi authored Oct 24, 2024
1 parent 94dfbe0 commit dd6d030
Show file tree
Hide file tree
Showing 51 changed files with 2,692 additions and 1,801 deletions.
73 changes: 73 additions & 0 deletions backend/pkg/integration-test/integration-test-util.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package integrationtests_test

import (
"context"
"testing"

"connectrpc.com/connect"
mgmtv1alpha1 "github.com/nucleuscloud/neosync/backend/gen/go/protos/mgmt/v1alpha1"
"github.com/nucleuscloud/neosync/backend/gen/go/protos/mgmt/v1alpha1/mgmtv1alpha1connect"
"github.com/stretchr/testify/require"
)

func CreatePersonalAccount(
ctx context.Context,
t *testing.T,
userclient mgmtv1alpha1connect.UserAccountServiceClient,
) string {
resp, err := userclient.SetPersonalAccount(ctx, connect.NewRequest(&mgmtv1alpha1.SetPersonalAccountRequest{}))
RequireNoErrResp(t, resp, err)
return resp.Msg.AccountId
}

func CreatePostgresConnection(
ctx context.Context,
t *testing.T,
connclient mgmtv1alpha1connect.ConnectionServiceClient,
accountId string,
name string,
pgurl string,
) *mgmtv1alpha1.Connection {
resp, err := connclient.CreateConnection(
ctx,
connect.NewRequest(&mgmtv1alpha1.CreateConnectionRequest{
AccountId: accountId,
Name: name,
ConnectionConfig: &mgmtv1alpha1.ConnectionConfig{
Config: &mgmtv1alpha1.ConnectionConfig_PgConfig{
PgConfig: &mgmtv1alpha1.PostgresConnectionConfig{
ConnectionConfig: &mgmtv1alpha1.PostgresConnectionConfig_Url{
Url: pgurl,
},
},
},
},
}),
)
RequireNoErrResp(t, resp, err)
return resp.Msg.GetConnection()
}

func SetUser(ctx context.Context, t *testing.T, client mgmtv1alpha1connect.UserAccountServiceClient) string {
resp, err := client.SetUser(ctx, connect.NewRequest(&mgmtv1alpha1.SetUserRequest{}))
RequireNoErrResp(t, resp, err)
return resp.Msg.GetUserId()
}

func CreateTeamAccount(ctx context.Context, t *testing.T, client mgmtv1alpha1connect.UserAccountServiceClient, name string) string {
resp, err := client.CreateTeamAccount(ctx, connect.NewRequest(&mgmtv1alpha1.CreateTeamAccountRequest{Name: name}))
RequireNoErrResp(t, resp, err)
return resp.Msg.AccountId
}

func RequireNoErrResp[T any](t testing.TB, resp *connect.Response[T], err error) {
t.Helper()
require.NoError(t, err)
require.NotNil(t, resp)
}

func RequireErrResp[T any](t testing.TB, resp *connect.Response[T], err error) {
t.Helper()
require.Error(t, err)
require.Nil(t, resp)
}
Loading

0 comments on commit dd6d030

Please sign in to comment.