Skip to content

Commit

Permalink
fix: Fix sweepers (#2800)
Browse files Browse the repository at this point in the history
- Bump timeout for integration tests
- Use HasSuffix function in all the sweepers
- Remove old conditional logic
- Fix TestAcc_AccountRoles_basic test
- Skip two use warehouse tests
  • Loading branch information
sfc-gh-asawicki authored May 15, 2024
1 parent 181b4d0 commit a01115e
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ test-acceptance: ## run acceptance tests
TF_ACC=1 SF_TF_ACC_TEST_CONFIGURE_CLIENT_ONCE=true TEST_SF_TF_REQUIRE_TEST_OBJECT_SUFFIX=1 go test -run "^TestAcc_" -v -cover -timeout=60m ./...

test-integration: ## run SDK integration tests
TEST_SF_TF_REQUIRE_TEST_OBJECT_SUFFIX=1 go test -run "^TestInt_" -v -cover -timeout=30m ./...
TEST_SF_TF_REQUIRE_TEST_OBJECT_SUFFIX=1 go test -run "^TestInt_" -v -cover -timeout=45m ./...

test-architecture: ## check architecture constraints between packages
go test ./pkg/architests/... -v
Expand Down
2 changes: 1 addition & 1 deletion pkg/datasources/roles_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TestAcc_Roles(t *testing.T) {
}

func TestAcc_AccountRoles_basic(t *testing.T) {
accountRoleNamePrefix := "account_roles_test_prefix_"
accountRoleNamePrefix := "account_roles_test_prefix_" + random.AlphaN(4)
accountRoleName1 := acc.TestClient().Ids.AlphaWithPrefix(accountRoleNamePrefix)
accountRoleName2 := acc.TestClient().Ids.AlphaWithPrefix(accountRoleNamePrefix)
accountRoleName3 := acc.TestClient().Ids.Alpha()
Expand Down
2 changes: 2 additions & 0 deletions pkg/resources/external_table_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
)

func TestAcc_ExternalTable_basic(t *testing.T) {
// TODO [SNOW-1423486]: unskip
t.Skipf("Skip because error %s; will be fixed in SNOW-1423486", "Error: 000606 (57P03): No active warehouse selected in the current session. Select an active warehouse with the 'use warehouse' command.")
awsBucketURL, awsKeyId, awsSecretKey := getExternalTableTestEnvsOrSkipTest(t)

name := acc.TestClient().Ids.Alpha()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
)

func TestAcc_UserPasswordPolicyAttachment(t *testing.T) {
// TODO [SNOW-1423486]: unskip
t.Skipf("Skip because error %s; will be fixed in SNOW-1423486", "Error: 000606 (57P03): No active warehouse selected in the current session. Select an active warehouse with the 'use warehouse' command.")
userName := acc.TestClient().Ids.Alpha()
NewUserName := acc.TestClient().Ids.Alpha()
passwordPolicyName := acc.TestClient().Ids.Alpha()
Expand Down
13 changes: 5 additions & 8 deletions pkg/sdk/sweepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ func SweepAfterAcceptanceTests(client *Client, suffix string) error {
return sweep(client, suffix)
}

// TODO [SNOW-955520]: create account-level objects with appropriate suffix during tests (only the sweeped ones for now?)
// TODO [SNOW-955520]: move this to test code
// TODO [SNOW-955520]: use if exists/use method from helper for dropping
// TODO [SNOW-867247]: sweep all missing account-level objects (like users, integrations, replication groups, network policies, ...)
Expand Down Expand Up @@ -106,7 +105,7 @@ func getFailoverGroupSweeper(client *Client, suffix string) func() error {
return fmt.Errorf("sweeping failover groups ended with error, err = %w", err)
}
for _, fg := range fgs {
if strings.HasPrefix(fg.Name, suffix) && fg.AccountLocator == currentAccount {
if strings.HasSuffix(fg.Name, suffix) && fg.AccountLocator == currentAccount {
log.Printf("[DEBUG] Dropping failover group %s", fg.ID().FullyQualifiedName())
if err := client.FailoverGroups.Drop(ctx, fg.ID(), nil); err != nil {
return fmt.Errorf("sweeping failover group %s ended with error, err = %w", fg.ID().FullyQualifiedName(), err)
Expand All @@ -129,7 +128,7 @@ func getShareSweeper(client *Client, suffix string) func() error {
return fmt.Errorf("sweeping shares ended with error, err = %w", err)
}
for _, share := range shares {
if share.Kind == ShareKindOutbound && strings.HasPrefix(share.Name.Name(), suffix) {
if share.Kind == ShareKindOutbound && strings.HasSuffix(share.Name.Name(), suffix) {
log.Printf("[DEBUG] Dropping share %s", share.ID().FullyQualifiedName())
if err := client.Shares.Drop(ctx, share.ID(), &DropShareOptions{IfExists: Bool(true)}); err != nil {
return fmt.Errorf("sweeping share %s ended with error, err = %w", share.ID().FullyQualifiedName(), err)
Expand All @@ -152,8 +151,7 @@ func getDatabaseSweeper(client *Client, suffix string) func() error {
return fmt.Errorf("sweeping databases ended with error, err = %w", err)
}
for _, db := range dbs {
// TODO [SNOW-955520]: remove "terraform_test_database" condition after this PR is merged
if strings.HasPrefix(db.Name, suffix) && db.Name != "SNOWFLAKE" && db.Name != "terraform_test_database" {
if strings.HasSuffix(db.Name, suffix) && db.Name != "SNOWFLAKE" {
log.Printf("[DEBUG] Dropping database %s", db.ID().FullyQualifiedName())
if err := client.Databases.Drop(ctx, db.ID(), nil); err != nil {
if strings.Contains(err.Error(), "Object found is of type 'APPLICATION', not specified type 'DATABASE'") {
Expand All @@ -180,8 +178,7 @@ func getWarehouseSweeper(client *Client, suffix string) func() error {
return fmt.Errorf("sweeping warehouses ended with error, err = %w", err)
}
for _, wh := range whs {
// TODO [SNOW-955520]: remove "terraform_test_database" condition after this PR is merged
if strings.HasPrefix(wh.Name, suffix) && wh.Name != "SNOWFLAKE" && wh.Name != "terraform_test_warehouse" {
if strings.HasSuffix(wh.Name, suffix) && wh.Name != "SNOWFLAKE" {
log.Printf("[DEBUG] Dropping warehouse %s", wh.ID().FullyQualifiedName())
if err := client.Warehouses.Drop(ctx, wh.ID(), nil); err != nil {
return fmt.Errorf("sweeping warehouse %s ended with error, err = %w", wh.ID().FullyQualifiedName(), err)
Expand All @@ -204,7 +201,7 @@ func getRoleSweeper(client *Client, suffix string) func() error {
return fmt.Errorf("sweeping roles ended with error, err = %w", err)
}
for _, role := range roles {
if strings.HasPrefix(role.Name, suffix) && !slices.Contains([]string{"ACCOUNTADMIN", "SECURITYADMIN", "SYSADMIN", "ORGADMIN", "USERADMIN", "PUBLIC"}, role.Name) {
if strings.HasSuffix(role.Name, suffix) && !slices.Contains([]string{"ACCOUNTADMIN", "SECURITYADMIN", "SYSADMIN", "ORGADMIN", "USERADMIN", "PUBLIC"}, role.Name) {
log.Printf("[DEBUG] Dropping role %s", role.ID().FullyQualifiedName())
if err := client.Roles.Drop(ctx, NewDropRoleRequest(role.ID())); err != nil {
return fmt.Errorf("sweeping role %s ended with error, err = %w", role.ID().FullyQualifiedName(), err)
Expand Down

0 comments on commit a01115e

Please sign in to comment.