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

feat: Upgrade view sdk #2969

Merged
merged 10 commits into from
Aug 6, 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
4 changes: 2 additions & 2 deletions pkg/acceptance/bettertestspoc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (w *WarehouseResourceParametersAssert) HasDefaultMaxConcurrencyLevel() *War

### Adding new Snowflake object assertions
Snowflake object assertions can be generated automatically. For object `abc` do the following:
- add object you want to generate to `allStructs` slice in the `assert/objectassert/gen/main/main.go`
- add object you want to generate to `allStructs` slice in the `assert/objectassert/gen/sdk_object_def.go`
- to add custom (not generated assertions) create file `abc_snowflake_ext.go` in the `objectassert` package. Example would be:
```go
func (w *WarehouseAssert) HasStateOneOf(expected ...sdk.WarehouseState) *WarehouseAssert {
Expand Down Expand Up @@ -77,7 +77,7 @@ func (w *WarehouseParametersAssert) HasDefaultMaxConcurrencyLevel() *WarehousePa
}
```

### Adding new models
### Adding new resource config model builders
Resource config model builders can be generated automatically. For object `abc` do the following:
- add object you want to generate to `allResourceSchemaDefs` slice in the `assert/resourceassert/gen/resource_schema_def.go`
- to add custom (not generated) config builder methods create file `warehouse_model_ext` in the `config/model` package. Example would be:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ var allStructs = []SdkObjectDef{
ObjectType: sdk.ObjectTypeWarehouse,
ObjectStruct: sdk.Warehouse{},
},
{
IdType: "sdk.SchemaObjectIdentifier",
ObjectType: sdk.ObjectTypeView,
ObjectStruct: sdk.View{},
},
}

func GetSdkObjectDetails() []genhelpers.SdkObjectDetails {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package objectassert

import (
"fmt"
"testing"

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

func (w *ViewAssert) HasCreatedOnNotEmpty() *ViewAssert {
w.AddAssertion(func(t *testing.T, o *sdk.View) error {
t.Helper()
if o.CreatedOn == "" {
return fmt.Errorf("expected created on not empty; got: %v", o.CreatedOn)
}
return nil
})
return w
}

func (v *ViewAssert) HasNonEmptyText() *ViewAssert {
v.AddAssertion(func(t *testing.T, o *sdk.View) error {
t.Helper()
if o.Text == "" {
return fmt.Errorf("expected non empty text")
}
return nil
})
return v
}

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

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

47 changes: 47 additions & 0 deletions pkg/acceptance/helpers/aggregation_policy_client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package helpers

import (
"context"
"fmt"
"testing"

"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk"
"github.com/stretchr/testify/require"
)

// TODO(SNOW-1564954): change raw sqls to proper client
type AggregationPolicyClient struct {
context *TestClientContext
ids *IdsGenerator
}

func NewAggregationPolicyClient(context *TestClientContext, idsGenerator *IdsGenerator) *AggregationPolicyClient {
return &AggregationPolicyClient{
context: context,
ids: idsGenerator,
}
}

func (c *AggregationPolicyClient) client() *sdk.Client {
return c.context.client
}

func (c *AggregationPolicyClient) CreateAggregationPolicy(t *testing.T) (sdk.SchemaObjectIdentifier, func()) {
t.Helper()
ctx := context.Background()

id := c.ids.RandomSchemaObjectIdentifier()
_, err := c.client().ExecForTests(ctx, fmt.Sprintf(`CREATE AGGREGATION POLICY %s AS () RETURNS AGGREGATION_CONSTRAINT -> AGGREGATION_CONSTRAINT(MIN_GROUP_SIZE => 5)`, id.Name()))
require.NoError(t, err)
return id, c.DropAggregationPolicyFunc(t, id)
}

func (c *AggregationPolicyClient) DropAggregationPolicyFunc(t *testing.T, id sdk.SchemaObjectIdentifier) func() {
t.Helper()
ctx := context.Background()

return func() {
_, err := c.client().ExecForTests(ctx, fmt.Sprintf(`DROP AGGREGATION POLICY IF EXISTS %s`, id.Name()))
require.NoError(t, err)
}
}
Loading
Loading