-
Notifications
You must be signed in to change notification settings - Fork 426
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Replace id generation in integration and acceptance tests part1 (
#2747) In order to move to the unified ID generation (connected with the changes in #2737) to stabilize parallel builds, the following changes were introduced inside this PR: - IdsGenerator was introduced in TestClient. It allows us to get the ids of the default objects and build the new identifiers with the desired suffix (indicating the current build). Most of the helpers were moved to use this generator to get old and new ids. There are still TODOs left there (there are helpers that get the name of the object from the caller - we have to ensure that the names are generated the same way, or they have a good reason to be different). Ids generator is exposed so that both integration and acceptance tests can use it. - Changed the generation method of resource/datasource names to the exposed method described below in all the acceptance tests. - Fixed the random.go file in the SDK (so that this one is used only in the SDK unit tests - read the content of the file below, it had the long comment describing the problems with this file): - renamed to random_test.go - unexported all the methods - switch to appropriate methods in integration/acceptance tests - Next part of the change is to check all identifier creations throughout helpers/acceptance tests/integration tests and switch to a proper generator. This is not finished. The following methods were attacked (the rest will be tackled in the next PR): - NewExternalObjectIdentifier - NewExternalObjectIdentifierFromFullyQualifiedName - NewAccountIdentifier - NewAccountIdentifierFromAccountLocator (moved to ids generator) - NewAccountIdentifierFromFullyQualifiedName (2 usages left in business critical skipped tests) - NewAccountObjectIdentifier (testAccCheckDatabaseExistence left with todo, grantOwnershipToTheCurrentRole, testAccCheckSharePrivilegesRevoked, sdk.NewAccountObjectIdentifier("ACCOUNTADMIN"), sdk.NewAccountObjectIdentifier("ORGADMIN"), sdk.NewAccountObjectIdentifier("NOT_EXISTING_ACCOUNT"), sdk.NewAccountObjectIdentifier("does_not_exist"), current role/user, sdk.NewAccountObjectIdentifier("<DB>")) - NewAccountObjectIdentifierFromFullyQualifiedName - other smaller changes: - removed warehouse 2 in acceptance tests for now - fixed `TestAcc_TaskOwnershipGrant_onFuture` test Left to be done regarding NewAccountObjectIdentifier: - `alterMaterializedViewQueryExternally` - `checkDatabaseAndSchemaDataRetentionTime` - `checkDatabaseSchemaAndTableDataRetentionTime` - `unsafe_execute_acceptance_test.go` - `alterViewOwnershipExternally` - check `app_role_1` - check hardcoded `filter_by_role`, `stproc1`, `sp_pi`, `filterByRole`, `records` - `CreateDatabaseWithName` (and other similar helpers) - check `setup_test.go` - ask @sfc-gh-jcieslak about `sdk.NewAccountObjectIdentifier("S3_STORAGE_INTEGRATION")`, `sdk.NewAccountObjectIdentifier("GCP_STORAGE_INTEGRATION")`, `sdk.NewAccountObjectIdentifier("AZURE_STORAGE_INTEGRATION")` - extract common helpers for `sdk.NewAccountObjectIdentifier("does_not_exist"` and similar
- Loading branch information
1 parent
424e393
commit cd4a914
Showing
213 changed files
with
1,598 additions
and
1,708 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
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
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
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
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
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
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
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
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
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,74 @@ | ||
package helpers | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" | ||
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" | ||
) | ||
|
||
type IdsGenerator struct { | ||
context *TestClientContext | ||
} | ||
|
||
func NewIdsGenerator(context *TestClientContext) *IdsGenerator { | ||
return &IdsGenerator{ | ||
context: context, | ||
} | ||
} | ||
|
||
func (c *IdsGenerator) DatabaseId() sdk.AccountObjectIdentifier { | ||
return sdk.NewAccountObjectIdentifier(c.context.database) | ||
} | ||
|
||
func (c *IdsGenerator) SchemaId() sdk.DatabaseObjectIdentifier { | ||
return sdk.NewDatabaseObjectIdentifier(c.context.database, c.context.schema) | ||
} | ||
|
||
func (c *IdsGenerator) WarehouseId() sdk.AccountObjectIdentifier { | ||
return sdk.NewAccountObjectIdentifier(c.context.warehouse) | ||
} | ||
|
||
func (c *IdsGenerator) AccountIdentifierWithLocator() sdk.AccountIdentifier { | ||
return sdk.NewAccountIdentifierFromAccountLocator(c.context.client.GetAccountLocator()) | ||
} | ||
|
||
func (c *IdsGenerator) newSchemaObjectIdentifier(name string) sdk.SchemaObjectIdentifier { | ||
return sdk.NewSchemaObjectIdentifier(c.context.database, c.context.schema, name) | ||
} | ||
|
||
func (c *IdsGenerator) RandomAccountObjectIdentifier() sdk.AccountObjectIdentifier { | ||
return sdk.NewAccountObjectIdentifier(c.Alpha()) | ||
} | ||
|
||
func (c *IdsGenerator) RandomAccountObjectIdentifierWithPrefix(prefix string) sdk.AccountObjectIdentifier { | ||
return sdk.NewAccountObjectIdentifier(c.AlphaWithPrefix(prefix)) | ||
} | ||
|
||
func (c *IdsGenerator) RandomAccountObjectIdentifierContaining(part string) sdk.AccountObjectIdentifier { | ||
return sdk.NewAccountObjectIdentifier(c.AlphaContaining(part)) | ||
} | ||
|
||
func (c *IdsGenerator) RandomSchemaObjectIdentifier() sdk.SchemaObjectIdentifier { | ||
return c.newSchemaObjectIdentifier(c.Alpha()) | ||
} | ||
|
||
func (c *IdsGenerator) Alpha() string { | ||
return c.AlphaN(6) | ||
} | ||
|
||
func (c *IdsGenerator) AlphaN(n int) string { | ||
return c.withTestObjectSuffix(strings.ToUpper(random.AlphaN(n))) | ||
} | ||
|
||
func (c *IdsGenerator) AlphaContaining(part string) string { | ||
return c.withTestObjectSuffix(c.Alpha() + part) | ||
} | ||
|
||
func (c *IdsGenerator) AlphaWithPrefix(prefix string) string { | ||
return c.withTestObjectSuffix(prefix + c.Alpha()) | ||
} | ||
|
||
func (c *IdsGenerator) withTestObjectSuffix(text string) string { | ||
return text + c.context.testObjectSuffix | ||
} |
Oops, something went wrong.