diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 552e6d9..76f1ee6 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -4,7 +4,8 @@ on: [push] jobs: build: - runs-on: [self-hosted, default] + #runs-on: [self-hosted, default] + runs-on: default steps: - uses: actions/checkout@v3 - name: Set up Go diff --git a/Makefile b/Makefile index 15b10af..9f03409 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,6 @@ test: ## run unit tests integration-test: ## run integration tests TEST_DIRECTORY=./internal/integration-tests go run gotest.tools/gotestsum@latest --format testname - $(MAKE) clean-workspaces download-openapi-specs: ## download openapi specs @echo "Downloading openapi specs" diff --git a/internal/integration-tests/setup_test.go b/internal/integration-tests/setup_test.go index d5f7a4c..0fb6750 100644 --- a/internal/integration-tests/setup_test.go +++ b/internal/integration-tests/setup_test.go @@ -5,10 +5,11 @@ package integrationtests import ( "context" "fmt" + "math/rand" "net/http" "os" - "strings" - "time" + + //"strings" "github.com/hashicorp/go-retryablehttp" "github.com/xataio/xata-go/xata" @@ -68,12 +69,11 @@ func setupDatabase() (*config, error) { ) db, err := databaseCli.Create(ctx, xata.CreateDatabaseRequest{ - DatabaseName: "db" + cfg.testID, + DatabaseName: "sdk-integration-test-go-" + cfg.testID, WorkspaceID: xata.String(cfg.wsID), Region: &cfg.region, - UI: &xata.UI{Color: xata.String("RED")}, BranchMetaData: &xata.BranchMetadata{ - Repository: xata.String("github.com/my/repository"), + Repository: xata.String("github.com/xataio/xata-go"), Branch: xata.String("feature-branch"), Stage: xata.String("testing"), Labels: &[]string{"development"}, @@ -354,64 +354,15 @@ func cleanup(cfg *config) error { return err } } - if cfg.wsID != "" { - workspaceCli, err := xata.NewWorkspacesClient( - xata.WithAPIKey(cfg.apiKey), - xata.WithHTTPClient(cfg.httpCli), - ) - if err != nil { - return err - } - - err = workspaceCli.Delete(ctx, cfg.wsID) - if err != nil { - return err - } - } return nil } func testIdentifier() string { - currentTime := time.Now() - - // Print the time - return fmt.Sprintf( - "integration-test_%d-%d-%d_%d_%d_%d", - currentTime.Year(), - currentTime.Month(), - currentTime.Day(), - currentTime.Hour(), - currentTime.Minute(), - currentTime.Second(), - ) -} - -func cleanAllWorkspaces() error { - ctx := context.Background() - apiKey, found := os.LookupEnv("XATA_API_KEY") - if !found { - return fmt.Errorf("%s not found in env vars", "XATA_API_KEY") - } - - workspaceCli, err := xata.NewWorkspacesClient(xata.WithAPIKey(apiKey), xata.WithHTTPClient(retryablehttp.NewClient().StandardClient())) - if err != nil { - return err + const letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234566789" + b := make([]byte, 8) + for i := range b { + b[i] = letters[rand.Intn(len(letters))] } - - listResponse, err := workspaceCli.List(ctx) - if err != nil { - return err - } - - for _, ws := range listResponse.Workspaces { - if strings.Contains(ws.Name, "integration-test") { - err = workspaceCli.Delete(ctx, ws.Id) - if err != nil { - return err - } - } - } - - return nil + return string(b) } diff --git a/internal/integration-tests/setup_test_test.go b/internal/integration-tests/setup_test_test.go index a5f2e1d..4639805 100644 --- a/internal/integration-tests/setup_test_test.go +++ b/internal/integration-tests/setup_test_test.go @@ -4,7 +4,6 @@ package integrationtests import ( "context" - "os" "testing" "github.com/stretchr/testify/assert" @@ -31,13 +30,3 @@ func Test_setup_cleanup(t *testing.T) { } }) } - -func Test_cleanupIntegrationWorkspaces(t *testing.T) { - if _, found := os.LookupEnv("CLEAN_UP_INTEGRATION_WORKSPACES"); !found { - t.Skip("skipping integration workspaces cleanup") - } - err := cleanAllWorkspaces() - if err != nil { - t.Fatal(err) - } -}