Skip to content

Commit

Permalink
Fix views tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-asawicki committed Sep 10, 2024
1 parent 85fcb4a commit 0bcd1f0
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 26 deletions.
4 changes: 2 additions & 2 deletions pkg/sdk/testint/materialized_views_gen_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,10 @@ func TestInt_MaterializedViews(t *testing.T) {
rowAccessPolicyReference, err := testClientHelper().PolicyReferences.GetPolicyReference(t, view.ID(), sdk.PolicyEntityDomainView)
require.NoError(t, err)
assert.Equal(t, rowAccessPolicy.Name, rowAccessPolicyReference.PolicyName)
assert.Equal(t, "ROW_ACCESS_POLICY", rowAccessPolicyReference.PolicyKind)
assert.Equal(t, sdk.PolicyKindRowAccessPolicy, rowAccessPolicyReference.PolicyKind)
assert.Equal(t, view.ID().Name(), rowAccessPolicyReference.RefEntityName)
assert.Equal(t, "MATERIALIZED_VIEW", rowAccessPolicyReference.RefEntityDomain)
assert.Equal(t, "ACTIVE", rowAccessPolicyReference.PolicyStatus)
assert.Equal(t, "ACTIVE", *rowAccessPolicyReference.PolicyStatus)
})

t.Run("drop materialized view: existing", func(t *testing.T) {
Expand Down
54 changes: 30 additions & 24 deletions pkg/sdk/testint/views_gen_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,16 @@ func TestInt_Views(t *testing.T) {

assertPolicyReference := func(t *testing.T, policyRef sdk.PolicyReference,
policyId sdk.SchemaObjectIdentifier,
policyType string,
policyKind sdk.PolicyKind,
viewId sdk.SchemaObjectIdentifier,
refColumnName *string,
) {
t.Helper()
assert.Equal(t, policyId.Name(), policyRef.PolicyName)
assert.Equal(t, policyType, policyRef.PolicyKind)
assert.Equal(t, policyKind, policyRef.PolicyKind)
assert.Equal(t, viewId.Name(), policyRef.RefEntityName)
assert.Equal(t, "VIEW", policyRef.RefEntityDomain)
assert.Equal(t, "ACTIVE", policyRef.PolicyStatus)
assert.Equal(t, "ACTIVE", *policyRef.PolicyStatus)
if refColumnName != nil {
assert.NotNil(t, policyRef.RefColumnName)
assert.Equal(t, *refColumnName, *policyRef.RefColumnName)
Expand Down Expand Up @@ -204,9 +204,9 @@ func TestInt_Views(t *testing.T) {
return cmp.Compare(x.PolicyKind, y.PolicyKind)
})

assertPolicyReference(t, rowAccessPolicyReferences[0], aggregationPolicy, "AGGREGATION_POLICY", view.ID(), nil)
assertPolicyReference(t, rowAccessPolicyReferences[0], aggregationPolicy, sdk.PolicyKindAggregationPolicy, view.ID(), nil)

assertPolicyReference(t, rowAccessPolicyReferences[1], rowAccessPolicy.ID(), "ROW_ACCESS_POLICY", view.ID(), nil)
assertPolicyReference(t, rowAccessPolicyReferences[1], rowAccessPolicy.ID(), sdk.PolicyKindRowAccessPolicy, view.ID(), nil)
require.NotNil(t, rowAccessPolicyReferences[1].RefArgColumnNames)
refArgColumnNames := sdk.ParseCommaSeparatedStringArray(*rowAccessPolicyReferences[1].RefArgColumnNames, true)
assert.Len(t, refArgColumnNames, 1)
Expand Down Expand Up @@ -244,8 +244,8 @@ func TestInt_Views(t *testing.T) {
return cmp.Compare(x.PolicyKind, y.PolicyKind)
})

assertPolicyReference(t, rowAccessPolicyReferences[0], maskingPolicy.ID(), "MASKING_POLICY", view.ID(), sdk.Pointer("col1"))
assertPolicyReference(t, rowAccessPolicyReferences[1], projectionPolicy, "PROJECTION_POLICY", view.ID(), sdk.Pointer("col1"))
assertPolicyReference(t, rowAccessPolicyReferences[0], maskingPolicy.ID(), sdk.PolicyKindMaskingPolicy, view.ID(), sdk.Pointer("col1"))
assertPolicyReference(t, rowAccessPolicyReferences[1], projectionPolicy, sdk.PolicyKindProjectionPolicy, view.ID(), sdk.Pointer("col1"))
})

t.Run("drop view: existing", func(t *testing.T) {
Expand Down Expand Up @@ -408,16 +408,17 @@ func TestInt_Views(t *testing.T) {
require.NoError(t, err)
require.Len(t, policyReferences, 1)

assertPolicyReference(t, policyReferences[0], maskingPolicy.ID(), "MASKING_POLICY", view.ID(), sdk.Pointer("ID"))
assertPolicyReference(t, policyReferences[0], maskingPolicy.ID(), sdk.PolicyKindMaskingPolicy, view.ID(), sdk.Pointer("ID"))

alterRequest = sdk.NewAlterViewRequest(id).WithUnsetMaskingPolicyOnColumn(
*sdk.NewViewUnsetColumnMaskingPolicyRequest("ID"),
)
err = client.Views.Alter(ctx, alterRequest)
require.NoError(t, err)

_, err = testClientHelper().PolicyReferences.GetPolicyReference(t, view.ID(), sdk.PolicyEntityDomainView)
require.Error(t, err, "no rows in result set")
references, err := testClientHelper().PolicyReferences.GetPolicyReferences(t, view.ID(), sdk.PolicyEntityDomainView)
require.NoError(t, err)
require.Empty(t, references)
})

t.Run("alter view: set and unset projection policy on column", func(t *testing.T) {
Expand All @@ -437,16 +438,17 @@ func TestInt_Views(t *testing.T) {
require.NoError(t, err)
require.Len(t, rowAccessPolicyReferences, 1)

assertPolicyReference(t, rowAccessPolicyReferences[0], projectionPolicy, "PROJECTION_POLICY", view.ID(), sdk.Pointer("ID"))
assertPolicyReference(t, rowAccessPolicyReferences[0], projectionPolicy, sdk.PolicyKindProjectionPolicy, view.ID(), sdk.Pointer("ID"))

alterRequest = sdk.NewAlterViewRequest(id).WithUnsetProjectionPolicyOnColumn(
*sdk.NewViewUnsetProjectionPolicyRequest("ID"),
)
err = client.Views.Alter(ctx, alterRequest)
require.NoError(t, err)

_, err = testClientHelper().PolicyReferences.GetPolicyReference(t, view.ID(), sdk.PolicyEntityDomainView)
require.Error(t, err, "no rows in result set")
references, err := testClientHelper().PolicyReferences.GetPolicyReferences(t, view.ID(), sdk.PolicyEntityDomainView)
require.NoError(t, err)
require.Empty(t, references)
})

t.Run("alter view: set and unset tags on column", func(t *testing.T) {
Expand Down Expand Up @@ -506,15 +508,16 @@ func TestInt_Views(t *testing.T) {
rowAccessPolicyReference, err := testClientHelper().PolicyReferences.GetPolicyReference(t, view.ID(), sdk.PolicyEntityDomainView)
require.NoError(t, err)

assertPolicyReference(t, *rowAccessPolicyReference, rowAccessPolicy.ID(), "ROW_ACCESS_POLICY", view.ID(), nil)
assertPolicyReference(t, *rowAccessPolicyReference, rowAccessPolicy.ID(), sdk.PolicyKindRowAccessPolicy, view.ID(), nil)

// remove policy
alterRequest = sdk.NewAlterViewRequest(id).WithDropRowAccessPolicy(*sdk.NewViewDropRowAccessPolicyRequest(rowAccessPolicy.ID()))
err = client.Views.Alter(ctx, alterRequest)
require.NoError(t, err)

_, err = testClientHelper().PolicyReferences.GetPolicyReference(t, view.ID(), sdk.PolicyEntityDomainView)
require.Error(t, err, "no rows in result set")
references, err := testClientHelper().PolicyReferences.GetPolicyReferences(t, view.ID(), sdk.PolicyEntityDomainView)
require.NoError(t, err)
require.Empty(t, references)

// add policy again
alterRequest = sdk.NewAlterViewRequest(id).WithAddRowAccessPolicy(*sdk.NewViewAddRowAccessPolicyRequest(rowAccessPolicy.ID(), []sdk.Column{{Value: "ID"}}))
Expand Down Expand Up @@ -542,8 +545,9 @@ func TestInt_Views(t *testing.T) {
err = client.Views.Alter(ctx, alterRequest)
require.NoError(t, err)

_, err = testClientHelper().PolicyReferences.GetPolicyReference(t, view.ID(), sdk.PolicyEntityDomainView)
require.Error(t, err, "no rows in result set")
references, err = testClientHelper().PolicyReferences.GetPolicyReferences(t, view.ID(), sdk.PolicyEntityDomainView)
require.NoError(t, err)
require.Empty(t, references)
})

t.Run("alter view: add and drop data metrics", func(t *testing.T) {
Expand Down Expand Up @@ -615,8 +619,9 @@ func TestInt_Views(t *testing.T) {
err = client.Views.Alter(ctx, alterRequest)
require.NoError(t, err)

_, err = testClientHelper().PolicyReferences.GetPolicyReference(t, view.ID(), sdk.PolicyEntityDomainView)
require.Error(t, err, "no rows in result set")
references, err := testClientHelper().PolicyReferences.GetPolicyReferences(t, view.ID(), sdk.PolicyEntityDomainView)
require.NoError(t, err)
require.Empty(t, references)
})

t.Run("alter view: set and unset aggregation policies", func(t *testing.T) {
Expand All @@ -637,7 +642,7 @@ func TestInt_Views(t *testing.T) {
require.NoError(t, err)
require.Len(t, rowAccessPolicyReferences, 1)

assertPolicyReference(t, rowAccessPolicyReferences[0], aggregationPolicy, "AGGREGATION_POLICY", view.ID(), nil)
assertPolicyReference(t, rowAccessPolicyReferences[0], aggregationPolicy, sdk.PolicyKindAggregationPolicy, view.ID(), nil)

// set policy with force
alterRequest = sdk.NewAlterViewRequest(id).WithSetAggregationPolicy(*sdk.NewViewSetAggregationPolicyRequest(aggregationPolicy2).
Expand All @@ -650,15 +655,16 @@ func TestInt_Views(t *testing.T) {
require.NoError(t, err)
require.Len(t, rowAccessPolicyReferences, 1)

assertPolicyReference(t, rowAccessPolicyReferences[0], aggregationPolicy2, "AGGREGATION_POLICY", view.ID(), nil)
assertPolicyReference(t, rowAccessPolicyReferences[0], aggregationPolicy2, sdk.PolicyKindAggregationPolicy, view.ID(), nil)

// remove policy
alterRequest = sdk.NewAlterViewRequest(id).WithUnsetAggregationPolicy(*sdk.NewViewUnsetAggregationPolicyRequest())
err = client.Views.Alter(ctx, alterRequest)
require.NoError(t, err)

_, err = testClientHelper().PolicyReferences.GetPolicyReference(t, view.ID(), sdk.PolicyEntityDomainView)
require.Error(t, err, "no rows in result set")
references, err := testClientHelper().PolicyReferences.GetPolicyReferences(t, view.ID(), sdk.PolicyEntityDomainView)
require.NoError(t, err)
require.Empty(t, references)
})

t.Run("show view: default", func(t *testing.T) {
Expand Down

0 comments on commit 0bcd1f0

Please sign in to comment.