Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-jcieslak committed Aug 29, 2024
1 parent 9cab92b commit a5e8e32
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 30 deletions.
9 changes: 0 additions & 9 deletions pkg/resources/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -525,18 +525,9 @@ func ReadView(withExternalChangesMarking bool) schema.ReadContextFunc {
return diag.FromErr(err)
}

if err = d.Set("name", view.Name); err != nil {
return diag.FromErr(err)
}
if err := d.Set(FullyQualifiedNameAttributeName, id.FullyQualifiedName()); err != nil {
return diag.FromErr(err)
}
if err = d.Set("database", view.DatabaseName); err != nil {
return diag.FromErr(err)
}
if err = d.Set("schema", view.SchemaName); err != nil {
return diag.FromErr(err)
}
if err = d.Set("copy_grants", view.HasCopyGrants()); err != nil {
return diag.FromErr(err)
}
Expand Down
21 changes: 11 additions & 10 deletions pkg/sdk/data_metric_function_references_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"log"
"strings"
)

type DataMetricFunctionReferences interface {
Expand All @@ -28,10 +29,10 @@ type dataMetricFunctionReferencesRow struct {
MetricDatabaseName string `db:"METRIC_DATABASE_NAME"`
MetricSchemaName string `db:"METRIC_SCHEMA_NAME"`
MetricName string `db:"METRIC_NAME"`
ArgumentSignature string `db:"ARGUMENT_SIGNATURE"`
DataType string `db:"DATA_TYPE"`
RefDatabaseName string `db:"REF_DATABASE_NAME"`
RefSchemaName string `db:"REF_SCHEMA_NAME"`
ArgumentSignature string `db:"METRIC_SIGNATURE"`
DataType string `db:"METRIC_DATA_TYPE"`
RefDatabaseName string `db:"REF_ENTITY_DATABASE_NAME"`
RefSchemaName string `db:"REF_ENTITY_SCHEMA_NAME"`
RefEntityName string `db:"REF_ENTITY_NAME"`
RefEntityDomain string `db:"REF_ENTITY_DOMAIN"`
RefArguments string `db:"REF_ARGUMENTS"`
Expand Down Expand Up @@ -63,14 +64,14 @@ type DataMetricFunctionReference struct {

func (row dataMetricFunctionReferencesRow) convert() *DataMetricFunctionReference {
x := &DataMetricFunctionReference{
MetricDatabaseName: row.MetricDatabaseName,
MetricSchemaName: row.MetricSchemaName,
MetricName: row.MetricName,
MetricDatabaseName: strings.Trim(row.MetricDatabaseName, `"`),
MetricSchemaName: strings.Trim(row.MetricSchemaName, `"`),
MetricName: strings.Trim(row.MetricName, `"`),
ArgumentSignature: row.ArgumentSignature,
DataType: row.DataType,
RefEntityDatabaseName: row.RefDatabaseName,
RefEntitySchemaName: row.RefSchemaName,
RefEntityName: row.RefEntityName,
RefEntityDatabaseName: strings.Trim(row.RefDatabaseName, `"`),
RefEntitySchemaName: strings.Trim(row.RefSchemaName, `"`),
RefEntityName: strings.Trim(row.RefEntityName, `"`),
RefEntityDomain: row.RefEntityDomain,
RefId: row.RefId,
Schedule: row.Schedule,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package testint

import (
"strings"
"testing"

"github.com/stretchr/testify/assert"

"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk"
"github.com/stretchr/testify/require"
)
Expand All @@ -12,7 +15,7 @@ func TestInt_DataMetricFunctionReferences(t *testing.T) {
ctx := testContext(t)

t.Run("view domain", func(t *testing.T) {
functionId := sdk.NewSchemaObjectIdentifier("SNOWFLAKE", "CORE", "AVG")
functionId := sdk.NewSchemaObjectIdentifier("SNOWFLAKE", "CORE", "BLANK_COUNT")
statement := "SELECT ROLE_NAME, ROLE_OWNER FROM INFORMATION_SCHEMA.APPLICABLE_ROLES"
view, viewCleanup := testClientHelper().View.CreateView(t, statement)
t.Cleanup(viewCleanup)
Expand All @@ -30,13 +33,18 @@ func TestInt_DataMetricFunctionReferences(t *testing.T) {
require.NoError(t, err)
require.Equal(t, 1, len(dmfs))
dmf := dmfs[0]
require.Equal(t, string(sdk.DataMetricFuncionRefEntityDomainView), dmf.RefEntityDomain)
require.Equal(t, functionId.DatabaseName(), dmf.MetricDatabaseName)
require.Equal(t, functionId.SchemaName(), dmf.MetricSchemaName)
require.Equal(t, functionId.Name(), dmf.MetricName)
require.Equal(t, view.ID().DatabaseName(), dmf.RefEntityDatabaseName)
require.Equal(t, view.ID().SchemaName(), dmf.RefEntitySchemaName)
require.Equal(t, view.ID().Name(), dmf.RefEntityName)
require.Equal(t, "*/5 * * * * UTC", dmf.Schedule)
assert.Equal(t, string(sdk.DataMetricFuncionRefEntityDomainView), strings.ToUpper(dmf.RefEntityDomain))
assert.Equal(t, functionId.DatabaseName(), dmf.MetricDatabaseName)
assert.Equal(t, functionId.SchemaName(), dmf.MetricSchemaName)
assert.Equal(t, functionId.Name(), dmf.MetricName)
assert.Equal(t, view.ID().DatabaseName(), dmf.RefEntityDatabaseName)
assert.Equal(t, view.ID().SchemaName(), dmf.RefEntitySchemaName)
assert.Equal(t, view.ID().Name(), dmf.RefEntityName)
assert.Equal(t, "TABLE(VARCHAR)", dmf.ArgumentSignature)
assert.Equal(t, "NUMBER(38,0)", dmf.DataType)
assert.NotEmpty(t, dmf.RefArguments)
assert.NotEmpty(t, dmf.RefId)
assert.Equal(t, "*/5 * * * * UTC", dmf.Schedule)
assert.Equal(t, string(sdk.DataMetricScheduleStatusStarted), dmf.ScheduleStatus)
})
}
4 changes: 2 additions & 2 deletions pkg/sdk/testint/views_gen_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -557,8 +557,8 @@ func TestInt_Views(t *testing.T) {
t.Cleanup(dataMetricFunction2Cleanup)

// set cron schedule
cron := "5 * * * * UTC"
alterRequest := sdk.NewAlterViewRequest(id).WithSetDataMetricSchedule(*sdk.NewViewSetDataMetricScheduleRequest(cron))
cron := "*/5 * * * * UTC"
alterRequest := sdk.NewAlterViewRequest(id).WithSetDataMetricSchedule(*sdk.NewViewSetDataMetricScheduleRequest("USING CRON " + cron))
err := client.Views.Alter(ctx, alterRequest)
require.NoError(t, err)

Expand Down

0 comments on commit a5e8e32

Please sign in to comment.