From a5e8e32e45a05a3a23a17d2570774842107c01a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Cie=C5=9Blak?= Date: Thu, 29 Aug 2024 11:17:36 +0200 Subject: [PATCH] Fix tests --- pkg/resources/view.go | 9 ------- .../data_metric_function_references_gen.go | 21 ++++++++------- ...unction_references_gen_integration_test.go | 26 ++++++++++++------- pkg/sdk/testint/views_gen_integration_test.go | 4 +-- 4 files changed, 30 insertions(+), 30 deletions(-) diff --git a/pkg/resources/view.go b/pkg/resources/view.go index 34d20c30a3..e9e929f2da 100644 --- a/pkg/resources/view.go +++ b/pkg/resources/view.go @@ -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) } diff --git a/pkg/sdk/data_metric_function_references_gen.go b/pkg/sdk/data_metric_function_references_gen.go index 59f2d50756..7170ae8f59 100644 --- a/pkg/sdk/data_metric_function_references_gen.go +++ b/pkg/sdk/data_metric_function_references_gen.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "log" + "strings" ) type DataMetricFunctionReferences interface { @@ -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"` @@ -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, diff --git a/pkg/sdk/testint/data_metric_function_references_gen_integration_test.go b/pkg/sdk/testint/data_metric_function_references_gen_integration_test.go index 25ca45c568..cf10780f10 100644 --- a/pkg/sdk/testint/data_metric_function_references_gen_integration_test.go +++ b/pkg/sdk/testint/data_metric_function_references_gen_integration_test.go @@ -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" ) @@ -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) @@ -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) }) } diff --git a/pkg/sdk/testint/views_gen_integration_test.go b/pkg/sdk/testint/views_gen_integration_test.go index b212348f2d..78003a45d6 100644 --- a/pkg/sdk/testint/views_gen_integration_test.go +++ b/pkg/sdk/testint/views_gen_integration_test.go @@ -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)