-
Notifications
You must be signed in to change notification settings - Fork 427
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
<!-- Feel free to delete comments as you fill this in --> - add acceptance clients for aggregation and projection policies (with jiras to use proper SDK clients) - adjust SDK to match snowflake - change handling of `PolicyReference` to be more generic - add new sturct `ExtendedIn` to handle SHOWs that can specify applications and applications packages (will be useful in other resources) - add more validations - add quotes for fields with column names - update resource and datasource to be compatible with sdk - update statuses of remaining objects - NOTE: view behavior is not consistent with docs, that is: - adding columns is not working - columns with options in CREATE are without () in docs - this is not correct, they need to be wrapped in (), this will be reported on doc-discuss ## Test Plan <!-- detail ways in which this PR has been tested or needs to be tested --> * [x] integration tests <!-- add more below if you think they are relevant --> * [x] unit tests ## References <!-- issues documentation links, etc --> https://docs.snowflake.com/en/sql-reference/sql/create-view#examples
- Loading branch information
1 parent
f4ae380
commit ef2d50a
Showing
31 changed files
with
2,024 additions
and
509 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
30 changes: 30 additions & 0 deletions
30
pkg/acceptance/bettertestspoc/assert/objectassert/view_snowflake_ext.go
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,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 | ||
} |
174 changes: 174 additions & 0 deletions
174
pkg/acceptance/bettertestspoc/assert/objectassert/view_snowflake_gen.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
106 changes: 106 additions & 0 deletions
106
pkg/acceptance/bettertestspoc/assert/resourceshowoutputassert/view_show_output_gen.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,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) | ||
} | ||
} |
Oops, something went wrong.