Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: invalid path for cleanup-test-schemas #163

Merged
merged 2 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ require (
github.com/trinodb/trino-go-client v0.315.0
github.com/youmark/pkcs8 v0.0.0-20240424034433-3c2c7870ae76
golang.org/x/crypto v0.25.0
golang.org/x/sync v0.7.0
google.golang.org/api v0.189.0
)

Expand Down Expand Up @@ -139,7 +140,6 @@ require (
golang.org/x/mod v0.18.0 // indirect
golang.org/x/net v0.27.0 // indirect
golang.org/x/oauth2 v0.21.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.22.0 // indirect
golang.org/x/term v0.22.0 // indirect
golang.org/x/text v0.16.0 // indirect
Expand Down
57 changes: 34 additions & 23 deletions sqlconnect/cmd/cleanup.go → sqlconnect/cmd/cleanup/cleanup.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"strings"

"github.com/tidwall/sjson"
"golang.org/x/sync/errgroup"

"github.com/rudderlabs/sqlconnect-go/sqlconnect"
"github.com/rudderlabs/sqlconnect-go/sqlconnect/internal/bigquery"
Expand All @@ -33,32 +34,42 @@
{Env: "TRINO_TEST_ENVIRONMENT_CREDENTIALS", Type: trino.DatabaseType},
}

g, ctx := errgroup.WithContext(context.Background())
g.SetLimit(4)

Check warning on line 38 in sqlconnect/cmd/cleanup/cleanup.go

View check run for this annotation

Codecov / codecov/patch

sqlconnect/cmd/cleanup/cleanup.go#L37-L38

Added lines #L37 - L38 were not covered by tests
for _, c := range cleanupConfigs {
configJSON, ok := os.LookupEnv(c.Env)
if !ok {
log.Fatalf("%s environment variable not set", c.Env)
}
if c.Fn != nil {
configJSON = c.Fn(configJSON)
}
db, err := sqlconnect.NewDB(c.Type, []byte(configJSON))
if err != nil {
log.Fatalf("[%s] failed to create db: %v", c.Type, err)
}
schemas, err := db.ListSchemas(context.Background())
if err != nil {
log.Fatalf("[%s] failed to list schemas: %v", c.Type, err)
}
for _, schema := range schemas {
if strings.Contains(strings.ToLower(schema.Name), "tsqlcon_") {
err := db.DropSchema(context.Background(), schema)
if err != nil {
log.Printf("[%s] failed to drop schema: %v", c.Type, err)
} else {
log.Printf("[%s] dropped schema %s", c.Type, schema)
c := c
g.Go(func() error {
configJSON, ok := os.LookupEnv(c.Env)
if !ok {
log.Fatalf("%s environment variable not set", c.Env)

Check warning on line 44 in sqlconnect/cmd/cleanup/cleanup.go

View check run for this annotation

Codecov / codecov/patch

sqlconnect/cmd/cleanup/cleanup.go#L40-L44

Added lines #L40 - L44 were not covered by tests
}
if c.Fn != nil {
configJSON = c.Fn(configJSON)

Check warning on line 47 in sqlconnect/cmd/cleanup/cleanup.go

View check run for this annotation

Codecov / codecov/patch

sqlconnect/cmd/cleanup/cleanup.go#L46-L47

Added lines #L46 - L47 were not covered by tests
}
db, err := sqlconnect.NewDB(c.Type, []byte(configJSON))
if err != nil {
log.Fatalf("[%s] failed to create db: %v", c.Type, err)

Check warning on line 51 in sqlconnect/cmd/cleanup/cleanup.go

View check run for this annotation

Codecov / codecov/patch

sqlconnect/cmd/cleanup/cleanup.go#L49-L51

Added lines #L49 - L51 were not covered by tests
}
schemas, err := db.ListSchemas(ctx)
if err != nil {
log.Fatalf("[%s] failed to list schemas: %v", c.Type, err)

Check warning on line 55 in sqlconnect/cmd/cleanup/cleanup.go

View check run for this annotation

Codecov / codecov/patch

sqlconnect/cmd/cleanup/cleanup.go#L53-L55

Added lines #L53 - L55 were not covered by tests
}
for _, schema := range schemas {
if strings.Contains(strings.ToLower(schema.Name), "tsqlcon_") {
err := db.DropSchema(ctx, schema)
if err != nil {
log.Printf("[%s] failed to drop schema: %v", c.Type, err)
} else {
log.Printf("[%s] dropped schema %s", c.Type, schema)

Check warning on line 63 in sqlconnect/cmd/cleanup/cleanup.go

View check run for this annotation

Codecov / codecov/patch

sqlconnect/cmd/cleanup/cleanup.go#L57-L63

Added lines #L57 - L63 were not covered by tests
}
}
}
}
return nil

Check warning on line 67 in sqlconnect/cmd/cleanup/cleanup.go

View check run for this annotation

Codecov / codecov/patch

sqlconnect/cmd/cleanup/cleanup.go#L67

Added line #L67 was not covered by tests
})
}

if err := g.Wait(); err != nil {
log.Fatalf("cleanup failed: %v", err)

Check warning on line 72 in sqlconnect/cmd/cleanup/cleanup.go

View check run for this annotation

Codecov / codecov/patch

sqlconnect/cmd/cleanup/cleanup.go#L71-L72

Added lines #L71 - L72 were not covered by tests
}
}

Expand Down