Skip to content

Commit

Permalink
refactor integ test setup
Browse files Browse the repository at this point in the history
  • Loading branch information
philkra committed Dec 22, 2023
1 parent c16ce12 commit 3cdf0f6
Showing 1 changed file with 10 additions and 19 deletions.
29 changes: 10 additions & 19 deletions internal/integration-tests/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,30 +31,21 @@ func setupDatabase() (*config, error) {
if !found {
return nil, fmt.Errorf("%s not found in env vars", "XATA_API_KEY")
}
// require workspace ID to come from the env var
// instead of creating new workspace on each client
wsID, found := os.LookupEnv("XATA_WORKSPACE_ID")
if !found {
return nil, fmt.Errorf("%s not found in env vars", "XATA_WORKSPACE_ID")
}

testID := testIdentifier()

cfg := &config{
apiKey: apiKey,
testID: testID,
wsID: wsID,
httpCli: retryablehttp.NewClient().StandardClient(),
}

workspaceCli, err := xata.NewWorkspacesClient(
xata.WithAPIKey(cfg.apiKey),
xata.WithHTTPClient(cfg.httpCli),
)
if err != nil {
return nil, err
}

ws, err := workspaceCli.Create(ctx, &xata.WorkspaceMeta{Name: "ws" + testID})
if err != nil {
return nil, err
}

cfg.wsID = ws.Id

databaseCli, err := xata.NewDatabasesClient(
xata.WithAPIKey(cfg.apiKey),
xata.WithHTTPClient(cfg.httpCli),
Expand All @@ -63,7 +54,7 @@ func setupDatabase() (*config, error) {
return nil, err
}

listRegionsResponse, err := databaseCli.GetRegionsWithWorkspaceID(ctx, ws.Id)
listRegionsResponse, err := databaseCli.GetRegionsWithWorkspaceID(ctx, cfg.wsID)
if err != nil {
return nil, err
}
Expand All @@ -77,8 +68,8 @@ func setupDatabase() (*config, error) {
)

db, err := databaseCli.Create(ctx, xata.CreateDatabaseRequest{
DatabaseName: "db" + testID,
WorkspaceID: xata.String(ws.Id),
DatabaseName: "db" + cfg.testID,
WorkspaceID: xata.String(cfg.wsID),
Region: &cfg.region,
UI: &xata.UI{Color: xata.String("RED")},
BranchMetaData: &xata.BranchMetadata{
Expand Down

0 comments on commit 3cdf0f6

Please sign in to comment.