-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CLI Sync postgres integration test + refactor (#2854)
- Loading branch information
1 parent
94dfbe0
commit dd6d030
Showing
51 changed files
with
2,692 additions
and
1,801 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
Oops, something went wrong.