From 62c747673a3f13adda2598133c8a5b6f1c13ea40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Cie=C5=9Blak?= Date: Tue, 26 Nov 2024 14:28:24 +0100 Subject: [PATCH] Changes after review --- pkg/datasources/common.go | 2 +- pkg/datasources/tasks.go | 2 -- pkg/internal/tracking/context.go | 4 ++-- pkg/internal/tracking/context_test.go | 2 +- pkg/internal/tracking/query_test.go | 6 +++--- pkg/sdk/testint/client_integration_test.go | 2 +- pkg/sdk/testint/dynamic_table_integration_test.go | 2 +- pkg/sdk/testint/materialized_views_gen_integration_test.go | 2 +- pkg/sdk/testint/views_gen_integration_test.go | 2 +- 9 files changed, 11 insertions(+), 13 deletions(-) diff --git a/pkg/datasources/common.go b/pkg/datasources/common.go index 7f4b27d566..9b4f354dda 100644 --- a/pkg/datasources/common.go +++ b/pkg/datasources/common.go @@ -2,10 +2,10 @@ package datasources import ( "context" + "fmt" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/tracking" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/provider/datasources" - "fmt" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/resources" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" diff --git a/pkg/datasources/tasks.go b/pkg/datasources/tasks.go index 69ba8b7fa7..356556dbf7 100644 --- a/pkg/datasources/tasks.go +++ b/pkg/datasources/tasks.go @@ -9,8 +9,6 @@ import ( "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/provider" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/resources" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/schemas" - "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) diff --git a/pkg/internal/tracking/context.go b/pkg/internal/tracking/context.go index 4f4045960c..8fdbf8c03f 100644 --- a/pkg/internal/tracking/context.go +++ b/pkg/internal/tracking/context.go @@ -54,8 +54,8 @@ func (m Metadata) validate() error { return errors.Join(errs...) } -// NewTestMetadata is a helper constructor that is used only for testing purposes -func NewTestMetadata(version string, resource resources.Resource, operation Operation) Metadata { +// newTestMetadata is a helper constructor that is used only for testing purposes +func newTestMetadata(version string, resource resources.Resource, operation Operation) Metadata { return Metadata{ SchemaVersion: CurrentSchemaVersion, Version: version, diff --git a/pkg/internal/tracking/context_test.go b/pkg/internal/tracking/context_test.go index cc929b4f64..18bb38d588 100644 --- a/pkg/internal/tracking/context_test.go +++ b/pkg/internal/tracking/context_test.go @@ -11,7 +11,7 @@ import ( ) func Test_Context(t *testing.T) { - metadata := NewTestMetadata("123", resources.Account, CreateOperation) + metadata := newTestMetadata("123", resources.Account, CreateOperation) newMetadata := NewVersionedDatasourceMetadata(datasources.Databases) ctx := context.Background() diff --git a/pkg/internal/tracking/query_test.go b/pkg/internal/tracking/query_test.go index d40261477c..83696b928b 100644 --- a/pkg/internal/tracking/query_test.go +++ b/pkg/internal/tracking/query_test.go @@ -47,7 +47,7 @@ func TestTrimMetadata(t *testing.T) { } func TestAppendMetadata(t *testing.T) { - metadata := NewTestMetadata("123", resources.Account, CreateOperation) + metadata := newTestMetadata("123", resources.Account, CreateOperation) sql := "SELECT 1" bytes, err := json.Marshal(metadata) @@ -61,7 +61,7 @@ func TestAppendMetadata(t *testing.T) { } func TestParseMetadata(t *testing.T) { - metadata := NewTestMetadata("123", resources.Account, CreateOperation) + metadata := newTestMetadata("123", resources.Account, CreateOperation) bytes, err := json.Marshal(metadata) require.NoError(t, err) sql := fmt.Sprintf("SELECT 1 --%s %s", MetadataPrefix, string(bytes)) @@ -91,7 +91,7 @@ func TestParseInvalidMetadataJson(t *testing.T) { } func TestParseMetadataFromInvalidSqlCommentPrefix(t *testing.T) { - metadata := NewTestMetadata("123", resources.Account, CreateOperation) + metadata := newTestMetadata("123", resources.Account, CreateOperation) sql := "SELECT 1" bytes, err := json.Marshal(metadata) diff --git a/pkg/sdk/testint/client_integration_test.go b/pkg/sdk/testint/client_integration_test.go index 7d98396c0f..1f0a3875df 100644 --- a/pkg/sdk/testint/client_integration_test.go +++ b/pkg/sdk/testint/client_integration_test.go @@ -12,7 +12,7 @@ import ( func TestInt_Client_AdditionalMetadata(t *testing.T) { client := testClient(t) - metadata := tracking.NewTestMetadata("v1.13.1002-rc-test", resources.Database, tracking.CreateOperation) + metadata := tracking.Metadata{Version: "v1.13.1002-rc-test", Resource: resources.Database.String(), Operation: tracking.CreateOperation} assertQueryMetadata := func(t *testing.T, queryId string) { t.Helper() diff --git a/pkg/sdk/testint/dynamic_table_integration_test.go b/pkg/sdk/testint/dynamic_table_integration_test.go index b7025d4e04..8eb130486c 100644 --- a/pkg/sdk/testint/dynamic_table_integration_test.go +++ b/pkg/sdk/testint/dynamic_table_integration_test.go @@ -56,7 +56,7 @@ func TestInt_DynamicTableCreateAndDrop(t *testing.T) { t.Run("create with usage tracking comment", func(t *testing.T) { id := testClientHelper().Ids.RandomSchemaObjectIdentifier() plainQuery := fmt.Sprintf("SELECT id FROM %s", tableTest.ID().FullyQualifiedName()) - query, err := tracking.AppendMetadata(plainQuery, tracking.NewVersionedMetadata(resources.DynamicTable, tracking.CreateOperation)) + query, err := tracking.AppendMetadata(plainQuery, tracking.NewVersionedResourceMetadata(resources.DynamicTable, tracking.CreateOperation)) require.NoError(t, err) err = client.DynamicTables.Create(ctx, sdk.NewCreateDynamicTableRequest(id, testClientHelper().Ids.WarehouseId(), sdk.TargetLag{ diff --git a/pkg/sdk/testint/materialized_views_gen_integration_test.go b/pkg/sdk/testint/materialized_views_gen_integration_test.go index 6ef58925e9..6cad7bcb93 100644 --- a/pkg/sdk/testint/materialized_views_gen_integration_test.go +++ b/pkg/sdk/testint/materialized_views_gen_integration_test.go @@ -115,7 +115,7 @@ func TestInt_MaterializedViews(t *testing.T) { t.Run("create materialized view: with usage tracking comment", func(t *testing.T) { id := testClientHelper().Ids.RandomSchemaObjectIdentifier() plainQuery := fmt.Sprintf("SELECT id FROM %s", table.ID().FullyQualifiedName()) - query, err := tracking.AppendMetadata(plainQuery, tracking.NewVersionedMetadata(resources.MaterializedView, tracking.CreateOperation)) + query, err := tracking.AppendMetadata(plainQuery, tracking.NewVersionedResourceMetadata(resources.MaterializedView, tracking.CreateOperation)) require.NoError(t, err) view := createMaterializedViewWithRequest(t, sdk.NewCreateMaterializedViewRequest(id, query)) diff --git a/pkg/sdk/testint/views_gen_integration_test.go b/pkg/sdk/testint/views_gen_integration_test.go index 3682a3ee09..df8db37ab8 100644 --- a/pkg/sdk/testint/views_gen_integration_test.go +++ b/pkg/sdk/testint/views_gen_integration_test.go @@ -172,7 +172,7 @@ func TestInt_Views(t *testing.T) { t.Run("create view: with usage tracking comment", func(t *testing.T) { id := testClientHelper().Ids.RandomSchemaObjectIdentifier() plainQuery := "SELECT NULL AS TYPE" - query, err := tracking.AppendMetadata(plainQuery, tracking.NewVersionedMetadata(resources.View, tracking.CreateOperation)) + query, err := tracking.AppendMetadata(plainQuery, tracking.NewVersionedResourceMetadata(resources.View, tracking.CreateOperation)) require.NoError(t, err) request := sdk.NewCreateViewRequest(id, query)