Skip to content

Commit

Permalink
chore: Clean old assertions (#3029)
Browse files Browse the repository at this point in the history
Clean old assertions:
- replace `checkBool`
- replace `snowflakechecks` for warehouse with already generated new
assertions
- replace `snowflakechecks` for database with new generated assertions
  - generated object assertions for the database
  - generated parameter assertions for the database
- written assertions for the database describe (they are not
generateable yet)

Other:
- renamed methods in `resource_helpers_read.go`
  • Loading branch information
sfc-gh-asawicki authored Sep 2, 2024
1 parent 426ddb1 commit ad657eb
Show file tree
Hide file tree
Showing 23 changed files with 934 additions and 376 deletions.
2 changes: 1 addition & 1 deletion pkg/acceptance/bettertestspoc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ it will result in:
- Replace `acceptance/snowflakechecks` with the new proposed Snowflake objects assertions.
- Support `showOutputValueUnset` and add a second function for each `show_output` attribute.
- Support `resourceAssertionTypeValueNotSet` for import checks (`panic` left currently).
- Add assertions for the `describe_output`.
- Add assertions for the `describe_output` and handle describe objects too.
- Add support for datasource tests (assertions and config builders).
- Consider overriding the assertions when invoking same check multiple times with different params (e.g. `Warehouse(...).HasType(X).HasType(Y)`; it could use the last-check-wins approach, to more easily reuse complex checks between the test steps).
- Consider not adding the check for `show_output` presence on creation (same with `parameters`). The majority of the use cases need it to be present but there are a few others (like conditional presence in the datasources). Currently, it seems that they should be always present in the resources, so no change is made. Later, with adding the support for the datasource tests, consider simple destructive implementation like:
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package objectassert

import (
"fmt"
"slices"
"testing"

acc "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance"

"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert"
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk"
)

// TODO [SNOW-1501905]: this file should be fully regenerated when adding and option to assert the results of describe
type DatabaseDescribeAssert struct {
*assert.SnowflakeObjectAssert[sdk.DatabaseDetails, sdk.AccountObjectIdentifier]
}

func DatabaseDescribe(t *testing.T, id sdk.AccountObjectIdentifier) *DatabaseDescribeAssert {
t.Helper()
return &DatabaseDescribeAssert{
assert.NewSnowflakeObjectAssertWithProvider(sdk.ObjectType("DATABASE_DETAILS"), id, acc.TestClient().Database.Describe),
}
}

func (d *DatabaseDescribeAssert) DoesNotContainPublicSchema() *DatabaseDescribeAssert {
d.AddAssertion(func(t *testing.T, o *sdk.DatabaseDetails) error {
t.Helper()
if slices.ContainsFunc(o.Rows, func(row sdk.DatabaseDetailsRow) bool { return row.Name == "PUBLIC" && row.Kind == "SCHEMA" }) {
return fmt.Errorf("expected database %s to not contain public schema", d.GetId())
}
return nil
})
return d
}

func (d *DatabaseDescribeAssert) ContainsPublicSchema() *DatabaseDescribeAssert {
d.AddAssertion(func(t *testing.T, o *sdk.DatabaseDetails) error {
t.Helper()
if !slices.ContainsFunc(o.Rows, func(row sdk.DatabaseDetailsRow) bool { return row.Name == "PUBLIC" && row.Kind == "SCHEMA" }) {
return fmt.Errorf("expected database %s to contain public schema", d.GetId())
}
return nil
})
return d
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ type SdkObjectDef struct {
}

var allStructs = []SdkObjectDef{
{
IdType: "sdk.AccountObjectIdentifier",
ObjectType: sdk.ObjectTypeDatabase,
ObjectStruct: sdk.Database{},
},
{
IdType: "sdk.DatabaseObjectIdentifier",
ObjectType: sdk.ObjectTypeDatabaseRole,
Expand All @@ -22,16 +27,16 @@ var allStructs = []SdkObjectDef{
ObjectType: sdk.ObjectTypeUser,
ObjectStruct: sdk.User{},
},
{
IdType: "sdk.AccountObjectIdentifier",
ObjectType: sdk.ObjectTypeWarehouse,
ObjectStruct: sdk.Warehouse{},
},
{
IdType: "sdk.SchemaObjectIdentifier",
ObjectType: sdk.ObjectTypeView,
ObjectStruct: sdk.View{},
},
{
IdType: "sdk.AccountObjectIdentifier",
ObjectType: sdk.ObjectTypeWarehouse,
ObjectStruct: sdk.Warehouse{},
},
}

func GetSdkObjectDetails() []genhelpers.SdkObjectDetails {
Expand Down
Loading

0 comments on commit ad657eb

Please sign in to comment.