Skip to content

Commit 20ee0eb

Browse files
chore: Adjust data source tests follow up 3 (snowflakedb#4166)
Follow up for snowflakedb#4115, addressing the following data sources - `account roles` - `database roles` - `masking policies` - `network policies` - `resource monitors` - `row access policies`
1 parent 23725df commit 20ee0eb

18 files changed

+926
-397
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package resourceshowoutputassert
2+
3+
import (
4+
"testing"
5+
6+
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert"
7+
)
8+
9+
func AccountRolesDatasourceShowOutput(t *testing.T, datasourceReference string) *RoleShowOutputAssert {
10+
t.Helper()
11+
12+
s := RoleShowOutputAssert{
13+
ResourceAssert: assert.NewDatasourceAssert(datasourceReference, "show_output", "account_roles.0."),
14+
}
15+
s.AddAssertion(assert.ValueSet("show_output.#", "1"))
16+
return &s
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package resourceshowoutputassert
2+
3+
import (
4+
"testing"
5+
6+
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert"
7+
)
8+
9+
func DatabaseRolesDatasourceShowOutput(t *testing.T, datasourceReference string) *DatabaseRoleShowOutputAssert {
10+
t.Helper()
11+
12+
s := DatabaseRoleShowOutputAssert{
13+
ResourceAssert: assert.NewDatasourceAssert(datasourceReference, "show_output", "database_roles.0."),
14+
}
15+
s.AddAssertion(assert.ValueSet("show_output.#", "1"))
16+
return &s
17+
}

pkg/acceptance/bettertestspoc/assert/resourceshowoutputassert/masking_policy_show_output_ext.go

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,28 @@ import (
66
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert"
77
)
88

9-
func (p *MaskingPolicyShowOutputAssert) HasCreatedOnNotEmpty() *MaskingPolicyShowOutputAssert {
10-
p.AddAssertion(assert.ResourceShowOutputValuePresent("created_on"))
11-
return p
12-
}
13-
149
// MaskingPoliciesDatasourceShowOutput is a temporary workaround to have better show output assertions in data source acceptance tests.
15-
func MaskingPoliciesDatasourceShowOutput(t *testing.T, name string) *MaskingPolicyShowOutputAssert {
10+
func MaskingPoliciesDatasourceShowOutput(t *testing.T, datasourceReference string) *MaskingPolicyShowOutputAssert {
1611
t.Helper()
1712

1813
m := MaskingPolicyShowOutputAssert{
19-
ResourceAssert: assert.NewDatasourceAssert("data."+name, "show_output", "masking_policies.0."),
14+
ResourceAssert: assert.NewDatasourceAssert(datasourceReference, "show_output", "masking_policies.0."),
2015
}
2116
m.AddAssertion(assert.ValueSet("show_output.#", "1"))
2217
return &m
2318
}
19+
20+
func (p *MaskingPolicyShowOutputAssert) HasCreatedOnNotEmpty() *MaskingPolicyShowOutputAssert {
21+
p.AddAssertion(assert.ResourceShowOutputValuePresent("created_on"))
22+
return p
23+
}
24+
25+
func (p *MaskingPolicyShowOutputAssert) HasOwnerNotEmpty() *MaskingPolicyShowOutputAssert {
26+
p.AddAssertion(assert.ResourceShowOutputValuePresent("owner"))
27+
return p
28+
}
29+
30+
func (p *MaskingPolicyShowOutputAssert) HasOwnerRoleTypeNotEmpty() *MaskingPolicyShowOutputAssert {
31+
p.AddAssertion(assert.ResourceShowOutputValuePresent("owner_role_type"))
32+
return p
33+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package resourceshowoutputassert
2+
3+
import (
4+
"testing"
5+
6+
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert"
7+
)
8+
9+
func NetworkPoliciesDatasourceShowOutput(t *testing.T, datasourceReference string) *NetworkPolicyShowOutputAssert {
10+
t.Helper()
11+
12+
n := NetworkPolicyShowOutputAssert{
13+
ResourceAssert: assert.NewDatasourceAssert(datasourceReference, "show_output", "network_policies.0."),
14+
}
15+
n.AddAssertion(assert.ValueSet("show_output.#", "1"))
16+
return &n
17+
}

pkg/acceptance/bettertestspoc/assert/resourceshowoutputassert/resource_monitor_show_output_ext.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import (
77
)
88

99
// ResourceMonitorDatasourceShowOutput is a temporary workaround to have better show output assertions in data source acceptance tests.
10-
func ResourceMonitorDatasourceShowOutput(t *testing.T, name string) *ResourceMonitorShowOutputAssert {
10+
func ResourceMonitorDatasourceShowOutput(t *testing.T, datasourceReference string) *ResourceMonitorShowOutputAssert {
1111
t.Helper()
1212

1313
u := ResourceMonitorShowOutputAssert{
14-
ResourceAssert: assert.NewDatasourceAssert("data."+name, "show_output", "resource_monitors.0."),
14+
ResourceAssert: assert.NewDatasourceAssert(datasourceReference, "show_output", "resource_monitors.0."),
1515
}
1616
u.AddAssertion(assert.ValueSet("show_output.#", "1"))
1717
return &u

pkg/acceptance/bettertestspoc/assert/resourceshowoutputassert/row_access_policy_show_output_ext.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ func (r *RowAccessPolicyShowOutputAssert) HasCreatedOnNotEmpty() *RowAccessPolic
1212
}
1313

1414
// RowAccessPoliciesDatasourceShowOutput is a temporary workaround to have better show output assertions in data source acceptance tests.
15-
func RowAccessPoliciesDatasourceShowOutput(t *testing.T, name string) *RowAccessPolicyShowOutputAssert {
15+
func RowAccessPoliciesDatasourceShowOutput(t *testing.T, datasourceReference string) *RowAccessPolicyShowOutputAssert {
1616
t.Helper()
1717

1818
r := RowAccessPolicyShowOutputAssert{
19-
ResourceAssert: assert.NewDatasourceAssert("data."+name, "show_output", "row_access_policies.0."),
19+
ResourceAssert: assert.NewDatasourceAssert(datasourceReference, "show_output", "row_access_policies.0."),
2020
}
2121
r.AddAssertion(assert.ValueSet("show_output.#", "1"))
2222
return &r

pkg/acceptance/bettertestspoc/config/datasourcemodel/account_roles_model_gen.go

Lines changed: 92 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/acceptance/bettertestspoc/config/datasourcemodel/database_roles_model_ext.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@ package datasourcemodel
22

33
import tfconfig "github.com/hashicorp/terraform-plugin-testing/config"
44

5+
func (d *DatabaseRolesModel) WithRows(rows int) *DatabaseRolesModel {
6+
return d.WithLimitValue(
7+
tfconfig.ObjectVariable(map[string]tfconfig.Variable{
8+
"rows": tfconfig.IntegerVariable(rows),
9+
}),
10+
)
11+
}
12+
513
func (d *DatabaseRolesModel) WithRowsAndFrom(rows int, from string) *DatabaseRolesModel {
614
return d.WithLimitValue(
715
tfconfig.ObjectVariable(map[string]tfconfig.Variable{

pkg/acceptance/bettertestspoc/config/datasourcemodel/gen/datasource_schema_def.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ var allDatasourcesSchemaDefs = []DatasourceSchemaDef{
2626
name: "Accounts",
2727
schema: datasources.Accounts().Schema,
2828
},
29+
{
30+
name: "AccountRoles",
31+
schema: datasources.AccountRoles().Schema,
32+
},
2933
{
3034
name: "AuthenticationPolicies",
3135
schema: datasources.AuthenticationPolicies().Schema,
@@ -82,6 +86,10 @@ var allDatasourcesSchemaDefs = []DatasourceSchemaDef{
8286
name: "ResourceMonitors",
8387
schema: datasources.ResourceMonitors().Schema,
8488
},
89+
{
90+
name: "RowAccessPolicies",
91+
schema: datasources.RowAccessPolicies().Schema,
92+
},
8593
{
8694
name: "Schemas",
8795
schema: datasources.Schemas().Schema,
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package datasourcemodel
2+
3+
import (
4+
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk"
5+
tfconfig "github.com/hashicorp/terraform-plugin-testing/config"
6+
)
7+
8+
func (m *MaskingPoliciesModel) WithInDatabase(databaseId sdk.AccountObjectIdentifier) *MaskingPoliciesModel {
9+
return m.WithInValue(
10+
tfconfig.ObjectVariable(map[string]tfconfig.Variable{
11+
"database": tfconfig.StringVariable(databaseId.Name()),
12+
}),
13+
)
14+
}
15+
16+
func (m *MaskingPoliciesModel) WithInSchema(schemaId sdk.DatabaseObjectIdentifier) *MaskingPoliciesModel {
17+
return m.WithInValue(
18+
tfconfig.ObjectVariable(map[string]tfconfig.Variable{
19+
"schema": tfconfig.StringVariable(schemaId.FullyQualifiedName()),
20+
}),
21+
)
22+
}
23+
24+
func (m *MaskingPoliciesModel) WithInAccount() *MaskingPoliciesModel {
25+
return m.WithInValue(
26+
tfconfig.ObjectVariable(map[string]tfconfig.Variable{
27+
"account": tfconfig.BoolVariable(true),
28+
}),
29+
)
30+
}
31+
32+
func (m *MaskingPoliciesModel) WithRows(rows int) *MaskingPoliciesModel {
33+
return m.WithLimitValue(
34+
tfconfig.ObjectVariable(map[string]tfconfig.Variable{
35+
"rows": tfconfig.IntegerVariable(rows),
36+
}),
37+
)
38+
}
39+
40+
func (m *MaskingPoliciesModel) WithRowsAndFrom(rows int, from string) *MaskingPoliciesModel {
41+
return m.WithLimitValue(
42+
tfconfig.ObjectVariable(map[string]tfconfig.Variable{
43+
"rows": tfconfig.IntegerVariable(rows),
44+
"from": tfconfig.StringVariable(from),
45+
}),
46+
)
47+
}

0 commit comments

Comments
 (0)