From 792665f7fea6cbe3c5df4906ba298efd2f6727a1 Mon Sep 17 00:00:00 2001 From: mnagaa Date: Sun, 30 Oct 2022 19:09:09 +0900 Subject: [PATCH] fix: golangci.yml to keep quality of codes (#1296) * fix: invalid golanci.yml format * fix: apply golangci * fix: apply make docs * fix: bad expressions detected with golangci-lint Co-authored-by: Scott Winkler --- .golangci.yml | 25 ++++++++++---- pkg/datasources/databases.go | 1 - pkg/provider/provider.go | 5 ++- pkg/provider/provider_test.go | 6 +++- .../database_grant_acceptance_test.go | 4 +-- pkg/resources/failover_group.go | 3 +- pkg/resources/file_format.go | 1 - pkg/resources/function_test.go | 24 ++++++------- pkg/resources/grant_helpers.go | 3 +- pkg/resources/grant_helpers_internal_test.go | 1 - pkg/resources/notification_integration.go | 34 +++++++++---------- .../notification_integration_test.go | 14 ++++---- pkg/resources/pipe.go | 6 ++-- pkg/resources/pipe_internal_test.go | 5 +-- pkg/resources/resource.go | 2 -- pkg/resources/role_grants.go | 2 -- pkg/resources/role_grants_internal_test.go | 4 --- pkg/resources/role_grants_test.go | 1 - pkg/resources/role_ownership_grant_test.go | 1 - pkg/resources/schema_grant_acceptance_test.go | 1 - pkg/resources/schema_grant_test.go | 1 + pkg/resources/stage_grant_acceptance_test.go | 2 +- pkg/resources/stage_grant_test.go | 1 + pkg/resources/table.go | 10 ------ pkg/resources/table_grant_acceptance_test.go | 2 +- pkg/resources/tag_association.go | 29 +++++++++++++--- pkg/resources/tag_grant.go | 1 - pkg/resources/task.go | 3 -- pkg/resources/task_internal_test.go | 1 - pkg/resources/user_ownership_grant_test.go | 1 - pkg/resources/user_public_keys.go | 2 +- pkg/resources/view_grant_acceptance_test.go | 1 - pkg/resources/view_test.go | 1 + pkg/snowflake/current_account_test.go | 11 +++--- pkg/snowflake/database.go | 1 + pkg/snowflake/escaping_test.go | 7 ++-- pkg/snowflake/failover_group.go | 2 +- pkg/snowflake/file_format.go | 2 +- pkg/snowflake/grant_test.go | 1 - pkg/snowflake/parser_test.go | 6 ++++ pkg/snowflake/pipe_test.go | 1 - pkg/snowflake/replication.go | 4 +-- pkg/snowflake/role_grant_test.go | 1 - pkg/snowflake/stage.go | 1 - pkg/snowflake/table.go | 15 -------- pkg/snowflake/table_constraint.go | 1 - pkg/snowflake/task.go | 1 - pkg/snowflake/validation.go | 1 - pkg/snowflake/validation_test.go | 1 + pkg/testhelpers/helpers.go | 1 - 50 files changed, 125 insertions(+), 130 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 8c8f567280..27bde3fdad 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,8 +1,19 @@ run: - linters: - enable: - - gofmt - - whitespace - - unparam - - scopelint - - godot + timeout: 5m + skip-files: [] + # skip-dirs: + +linters-settings: + misspell: + locale: US + +linters: + disable-all: true + enable: + - gofmt + - whitespace + # - unparam + - exportloopref + - godot + # - gocritic + - misspell diff --git a/pkg/datasources/databases.go b/pkg/datasources/databases.go index 25a8018834..a147b913d7 100644 --- a/pkg/datasources/databases.go +++ b/pkg/datasources/databases.go @@ -117,7 +117,6 @@ func ReadDatabases(d *schema.ResourceData, meta interface{}) error { } } databases = append(databases, dbR) - } databasesErr := d.Set("databases", databases) if databasesErr != nil { diff --git a/pkg/provider/provider.go b/pkg/provider/provider.go index b290872a5f..d45fde28d6 100644 --- a/pkg/provider/provider.go +++ b/pkg/provider/provider.go @@ -363,8 +363,8 @@ func DSN( host string, protocol string, port int, - warehouse string) (string, error) { - + warehouse string, +) (string, error) { // us-west-2 is Snowflake's default region, but if you actually specify that it won't trigger the default code // https://github.com/snowflakedb/gosnowflake/blob/52137ce8c32eaf93b0bd22fc5c7297beff339812/dsn.go#L61 if region == "us-west-2" { @@ -503,7 +503,6 @@ func GetOauthAccessToken( clientID, clientSecret string, data url.Values) (string, error) { - client := &http.Client{} request, err := GetOauthRequest(strings.NewReader(data.Encode()), endPoint, clientID, clientSecret) if err != nil { diff --git a/pkg/provider/provider_test.go b/pkg/provider/provider_test.go index fcb2ec09ad..d496bdb876 100644 --- a/pkg/provider/provider_test.go +++ b/pkg/provider/provider_test.go @@ -51,6 +51,7 @@ func TestDSN(t *testing.T) { "user4:pass4@zha1234.us-east-1.privatelink.snowflakecomputing.com:8443?account=acct4&application=terraform-provider-snowflake&ocspFailOpen=true&role=role4&validateDefaultParameters=true", false}, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { got, err := provider.DSN(tt.args.account, tt.args.user, tt.args.password, tt.args.browserAuth, "", "", "", "", tt.args.region, tt.args.role, tt.args.host, tt.args.protocol, tt.args.port, "") if (err != nil) != tt.wantErr { @@ -90,6 +91,7 @@ func TestOAuthDSN(t *testing.T) { "", true}, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { got, err := provider.DSN(tt.args.account, tt.args.user, "", false, "", "", "", tt.args.oauthAccessToken, tt.args.region, tt.args.role, tt.args.host, tt.args.protocol, tt.args.port, "") @@ -125,6 +127,7 @@ func TestGetOauthDATA(t *testing.T) { false}, } for _, tt := range cases { + tt := tt t.Run(tt.name, func(t *testing.T) { got := provider.GetOauthData(tt.param.refreshToken, tt.param.redirectURL) want, err := url.ParseQuery(tt.want) @@ -135,7 +138,6 @@ func TestGetOauthDATA(t *testing.T) { if !reflect.DeepEqual(got, want) { t.Errorf("GetData() = %v, want %v", got, tt.want) } - }) } } @@ -162,6 +164,7 @@ func TestGetOauthResponse(t *testing.T) { false}, } for _, tt := range cases { + tt := tt t.Run(tt.name, func(t *testing.T) { got, err := provider.GetOauthRequest(strings.NewReader(tt.param.dataStuff), tt.param.endpoint, tt.param.clientid, tt.param.clientscret) if err != nil { @@ -216,6 +219,7 @@ func TestGetOauthAccessToken(t *testing.T) { "404", "", false}, } for _, tt := range cases { + tt := tt t.Run(tt.name, func(t *testing.T) { client := NewTestClient(func(req *http.Request) *http.Response { // Test request parameters diff --git a/pkg/resources/database_grant_acceptance_test.go b/pkg/resources/database_grant_acceptance_test.go index fc8ee7b7e5..57fa5f556b 100644 --- a/pkg/resources/database_grant_acceptance_test.go +++ b/pkg/resources/database_grant_acceptance_test.go @@ -10,7 +10,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" ) -func testRolesAndShares(t *testing.T, path string, roles, shares []string) func(*terraform.State) error { +func testRolesAndShares(t *testing.T, path string, roles []string) func(*terraform.State) error { t.Helper() return func(state *terraform.State) error { is := state.RootModule().Resources[path].Primary @@ -49,7 +49,7 @@ func TestAcc_DatabaseGrant(t *testing.T) { resource.TestCheckResourceAttr("snowflake_database_grant.test", "roles.#", "1"), resource.TestCheckResourceAttr("snowflake_database_grant.test", "shares.#", "1"), resource.TestCheckResourceAttr("snowflake_database_grant.test", "shares.#", "1"), - testRolesAndShares(t, "snowflake_database_grant.test", []string{roleName}, []string{shareName}), + testRolesAndShares(t, "snowflake_database_grant.test", []string{roleName}), ), }, // IMPORT diff --git a/pkg/resources/failover_group.go b/pkg/resources/failover_group.go index d467f1dcbe..6b0c4a531b 100644 --- a/pkg/resources/failover_group.go +++ b/pkg/resources/failover_group.go @@ -276,7 +276,6 @@ func ReadFailoverGroup(d *schema.ResourceData, meta interface{}) error { found := false for _, fg := range failoverGroups { - if fg.Name.String == name && fg.AccountLocator.String == accountLocator { found = true err = d.Set("name", fg.Name.String) @@ -300,7 +299,7 @@ func ReadFailoverGroup(d *schema.ResourceData, meta interface{}) error { } // this is basically a hack to get around the fact that the API returns the object types in a different order than what is set - // this logic could also be put in the diff supress function, but I think it is better to do it here + // this logic could also be put in the diff suppress function, but I think it is better to do it here. currentObjectTypeList := d.Get("object_types").(*schema.Set).List() if len(currentObjectTypeList) != len(objectTypes) { log.Printf("[DEBUG] object types are different, current: %v, new: %v", currentObjectTypeList, objectTypes) diff --git a/pkg/resources/file_format.go b/pkg/resources/file_format.go index 635cf072c6..9ee2c6bcb9 100644 --- a/pkg/resources/file_format.go +++ b/pkg/resources/file_format.go @@ -774,7 +774,6 @@ func UpdateFileFormat(d *schema.ResourceData, meta interface{}) error { if err != nil { return errors.Wrapf(err, "error updating file format file extension on %v", d.Id()) } - } if d.HasChange("skip_header") { diff --git a/pkg/resources/function_test.go b/pkg/resources/function_test.go index 30a5bc38bd..6be5415449 100644 --- a/pkg/resources/function_test.go +++ b/pkg/resources/function_test.go @@ -20,18 +20,18 @@ func prepDummyFunctionResource(t *testing.T) *schema.ResourceData { argument1 := map[string]interface{}{"name": "data", "type": "varchar"} argument2 := map[string]interface{}{"name": "event_dt", "type": "date"} in := map[string]interface{}{ - "name": "my_funct", - "database": "my_db", - "schema": "my_schema", - "arguments": []interface{}{argument1, argument2}, - "language": "PYTHON", - "null_input_behaviour": "CALLED ON NULL INPUT", - "return_behavior": "VOLATILE", - "runtime_version": "3.8", - "packages": []interface{}{"numpy", "pandas"}, - "handler": "add_py", - "return_type": "varchar", - "statement": functionBody, //var message = DATA + DATA;return message + "name": "my_funct", + "database": "my_db", + "schema": "my_schema", + "arguments": []interface{}{argument1, argument2}, + "language": "PYTHON", + "null_input_behavior": "CALLED ON NULL INPUT", + "return_behavior": "VOLATILE", + "runtime_version": "3.8", + "packages": []interface{}{"numpy", "pandas"}, + "handler": "add_py", + "return_type": "varchar", + "statement": functionBody, //var message = DATA + DATA;return message } d := function(t, "my_db|my_schema|my_funct|VARCHAR-DATE", in) return d diff --git a/pkg/resources/grant_helpers.go b/pkg/resources/grant_helpers.go index 81d651194e..9341b00e62 100644 --- a/pkg/resources/grant_helpers.go +++ b/pkg/resources/grant_helpers.go @@ -206,7 +206,8 @@ func readGenericGrant( grantSchema map[string]*schema.Schema, builder snowflake.GrantBuilder, futureObjects bool, - validPrivileges PrivilegeSet) error { + validPrivileges PrivilegeSet, +) error { db := meta.(*sql.DB) var grants []*grant var err error diff --git a/pkg/resources/grant_helpers_internal_test.go b/pkg/resources/grant_helpers_internal_test.go index 4209f29504..0ea97299e1 100644 --- a/pkg/resources/grant_helpers_internal_test.go +++ b/pkg/resources/grant_helpers_internal_test.go @@ -132,7 +132,6 @@ func TestGrantLegacyID(t *testing.T) { r.Equal("priv", grant.Privilege) r.Equal([]string{}, grant.Roles) r.Equal(false, grant.GrantOption) - } func TestGrantIDFromStringRoleGrant(t *testing.T) { diff --git a/pkg/resources/notification_integration.go b/pkg/resources/notification_integration.go index 0b88abe91a..afc65bda7f 100644 --- a/pkg/resources/notification_integration.go +++ b/pkg/resources/notification_integration.go @@ -13,17 +13,17 @@ import ( var notificationIntegrationSchema = map[string]*schema.Schema{ // The first part of the schema is shared between all integration vendors - "name": &schema.Schema{ + "name": { Type: schema.TypeString, Required: true, ForceNew: true, }, - "enabled": &schema.Schema{ + "enabled": { Type: schema.TypeBool, Optional: true, Default: true, }, - "type": &schema.Schema{ + "type": { Type: schema.TypeString, Optional: true, Default: "QUEUE", @@ -31,7 +31,7 @@ var notificationIntegrationSchema = map[string]*schema.Schema{ Description: "A type of integration", ForceNew: true, }, - "direction": &schema.Schema{ + "direction": { Type: schema.TypeString, Optional: true, ValidateFunc: validation.StringInSlice([]string{"INBOUND", "OUTBOUND"}, true), @@ -39,24 +39,24 @@ var notificationIntegrationSchema = map[string]*schema.Schema{ ForceNew: true, }, // This part of the schema is the cloudProviderParams in the Snowflake documentation and differs between vendors - "notification_provider": &schema.Schema{ + "notification_provider": { Type: schema.TypeString, Optional: true, ValidateFunc: validation.StringInSlice([]string{"AZURE_STORAGE_QUEUE", "AWS_SQS", "AWS_SNS", "GCP_PUBSUB"}, true), Description: "The third-party cloud message queuing service (e.g. AZURE_STORAGE_QUEUE, AWS_SQS, AWS_SNS)", ForceNew: true, }, - "azure_storage_queue_primary_uri": &schema.Schema{ + "azure_storage_queue_primary_uri": { Type: schema.TypeString, Optional: true, Description: "The queue ID for the Azure Queue Storage queue created for Event Grid notifications", }, - "azure_tenant_id": &schema.Schema{ + "azure_tenant_id": { Type: schema.TypeString, Optional: true, Description: "The ID of the Azure Active Directory tenant used for identity management", }, - "aws_sqs_external_id": &schema.Schema{ + "aws_sqs_external_id": { Type: schema.TypeString, Computed: true, Description: "The external ID that Snowflake will use when assuming the AWS role", @@ -66,17 +66,17 @@ var notificationIntegrationSchema = map[string]*schema.Schema{ Computed: true, Description: "The Snowflake user that will attempt to assume the AWS role.", }, - "aws_sqs_arn": &schema.Schema{ + "aws_sqs_arn": { Type: schema.TypeString, Optional: true, Description: "AWS SQS queue ARN for notification integration to connect to", }, - "aws_sqs_role_arn": &schema.Schema{ + "aws_sqs_role_arn": { Type: schema.TypeString, Optional: true, Description: "AWS IAM role ARN for notification integration to assume", }, - "aws_sns_external_id": &schema.Schema{ + "aws_sns_external_id": { Type: schema.TypeString, Computed: true, Description: "The external ID that Snowflake will use when assuming the AWS role", @@ -86,32 +86,32 @@ var notificationIntegrationSchema = map[string]*schema.Schema{ Computed: true, Description: "The Snowflake user that will attempt to assume the AWS role.", }, - "aws_sns_topic_arn": &schema.Schema{ + "aws_sns_topic_arn": { Type: schema.TypeString, Optional: true, Description: "AWS SNS Topic ARN for notification integration to connect to", }, - "aws_sns_role_arn": &schema.Schema{ + "aws_sns_role_arn": { Type: schema.TypeString, Optional: true, Description: "AWS IAM role ARN for notification integration to assume", }, - "comment": &schema.Schema{ + "comment": { Type: schema.TypeString, Optional: true, Description: "A comment for the integration", }, - "created_on": &schema.Schema{ + "created_on": { Type: schema.TypeString, Computed: true, Description: "Date and time when the notification integration was created.", }, - "gcp_pubsub_subscription_name": &schema.Schema{ + "gcp_pubsub_subscription_name": { Type: schema.TypeString, Optional: true, Description: "The subscription id that Snowflake will listen to when using the GCP_PUBSUB provider.", }, - "gcp_pubsub_service_account": &schema.Schema{ + "gcp_pubsub_service_account": { Type: schema.TypeString, Computed: true, Description: "The GCP service account identifier that Snowflake will use when assuming the GCP role", diff --git a/pkg/resources/notification_integration_test.go b/pkg/resources/notification_integration_test.go index 087b409a31..32f7b7ee5b 100644 --- a/pkg/resources/notification_integration_test.go +++ b/pkg/resources/notification_integration_test.go @@ -70,14 +70,15 @@ func TestNotificationIntegrationCreate(t *testing.T) { expectSQL: `^CREATE NOTIFICATION INTEGRATION "test_notification_integration" COMMENT='great comment' GCP_PUBSUB_SUBSCRIPTION_NAME='some-gcp-sub-name' NOTIFICATION_PROVIDER='GCP_PUBSUB' TYPE='QUEUE' ENABLED=true$`, }, } - for _, testCase := range testCases { + for _, tc := range testCases { + tc := tc r := require.New(t) - d := schema.TestResourceDataRaw(t, resources.NotificationIntegration().Schema, testCase.raw) + d := schema.TestResourceDataRaw(t, resources.NotificationIntegration().Schema, tc.raw) r.NotNil(d) WithMockDb(t, func(db *sql.DB, mock sqlmock.Sqlmock) { - mock.ExpectExec(testCase.expectSQL).WillReturnResult(sqlmock.NewResult(1, 1)) - expectReadNotificationIntegration(mock, testCase.notificationProvider) + mock.ExpectExec(tc.expectSQL).WillReturnResult(sqlmock.NewResult(1, 1)) + expectReadNotificationIntegration(mock, tc.notificationProvider) err := resources.CreateNotificationIntegration(d, db) r.NoError(err) @@ -102,13 +103,14 @@ func TestNotificationIntegrationRead(t *testing.T) { notificationProvider: "GCP_PUBSUB", }, } - for _, testCase := range testCases { + for _, tc := range testCases { + tc := tc r := require.New(t) d := notificationIntegration(t, "test_notification_integration", map[string]interface{}{"name": "test_notification_integration"}) WithMockDb(t, func(db *sql.DB, mock sqlmock.Sqlmock) { - expectReadNotificationIntegration(mock, testCase.notificationProvider) + expectReadNotificationIntegration(mock, tc.notificationProvider) err := resources.ReadNotificationIntegration(d, db) r.NoError(err) diff --git a/pkg/resources/pipe.go b/pkg/resources/pipe.go index 5e6f129d03..47244aa5f7 100644 --- a/pkg/resources/pipe.go +++ b/pkg/resources/pipe.go @@ -61,12 +61,12 @@ var pipeSchema = map[string]*schema.Schema{ ForceNew: true, Description: "Specifies the Amazon Resource Name (ARN) for the SNS topic for your S3 bucket.", }, - "integration": &schema.Schema{ + "integration": { Type: schema.TypeString, Optional: true, Description: "Specifies an integration for the pipe.", }, - "notification_channel": &schema.Schema{ + "notification_channel": { Type: schema.TypeString, Computed: true, Description: "Amazon Resource Name of the Amazon SQS queue for the stage named in the DEFINITION column.", @@ -76,7 +76,7 @@ var pipeSchema = map[string]*schema.Schema{ Computed: true, Description: "Name of the role that owns the pipe.", }, - "error_integration": &schema.Schema{ + "error_integration": { Type: schema.TypeString, Optional: true, Description: "Specifies the name of the notification integration used for error notifications.", diff --git a/pkg/resources/pipe_internal_test.go b/pkg/resources/pipe_internal_test.go index 62f3a93ea4..ee67e0ed35 100644 --- a/pkg/resources/pipe_internal_test.go +++ b/pkg/resources/pipe_internal_test.go @@ -159,10 +159,11 @@ func TestPipeCopyStatementDiffSuppress(t *testing.T) { }, } - for name, testCase := range testCases { + for name, tc := range testCases { + tc := tc t.Run(name, func(t *testing.T) { r := require.New(t) - r.Equal(testCase.expected, pipeCopyStatementDiffSuppress("", testCase.declared, testCase.showPipes, nil)) + r.Equal(tc.expected, pipeCopyStatementDiffSuppress("", tc.declared, tc.showPipes, nil)) }) } } diff --git a/pkg/resources/resource.go b/pkg/resources/resource.go index 8ad9788750..3ef6eb85b0 100644 --- a/pkg/resources/resource.go +++ b/pkg/resources/resource.go @@ -38,7 +38,6 @@ func CreateResource( case schema.TypeSet: valList := expandStringList(val.(*schema.Set).List()) qb.SetStringList(field, valList) - } } } @@ -108,7 +107,6 @@ func UpdateResource( valList := expandStringList(val.(*schema.Set).List()) qb.SetStringList(field, valList) } - } if d.HasChange("tag") { log.Println("[DEBUG] updating tags") diff --git a/pkg/resources/role_grants.go b/pkg/resources/role_grants.go index 343ec8d93f..f1b8db0dca 100644 --- a/pkg/resources/role_grants.go +++ b/pkg/resources/role_grants.go @@ -186,7 +186,6 @@ func readGrants(db *sql.DB, roleName string) ([]*roleGrant, error) { return nil, err } grants = append(grants, g) - } for _, g := range grants { @@ -252,7 +251,6 @@ func revokeRoleFromUser(db *sql.DB, role1, user string) error { } } return err - } func UpdateRoleGrants(d *schema.ResourceData, meta interface{}) error { diff --git a/pkg/resources/role_grants_internal_test.go b/pkg/resources/role_grants_internal_test.go index f9b0effb16..e26a5fd029 100644 --- a/pkg/resources/role_grants_internal_test.go +++ b/pkg/resources/role_grants_internal_test.go @@ -50,9 +50,7 @@ func Test_revokeRoleFromRole(t *testing.T) { mock.ExpectExec(`REVOKE ROLE "foo" FROM ROLE "bar"`).WillReturnResult(sqlmock.NewResult(1, 1)) err := revokeRoleFromRole(db, "foo", "bar") r.NoError(err) - }) - } func Test_revokeRoleFromUser(t *testing.T) { r := require.New(t) @@ -60,7 +58,5 @@ func Test_revokeRoleFromUser(t *testing.T) { mock.ExpectExec(`REVOKE ROLE "foo" FROM USER "bar"`).WillReturnResult(sqlmock.NewResult(1, 1)) err := revokeRoleFromUser(db, "foo", "bar") r.NoError(err) - }) - } diff --git a/pkg/resources/role_grants_test.go b/pkg/resources/role_grants_test.go index 865c54b401..da09fa9b78 100644 --- a/pkg/resources/role_grants_test.go +++ b/pkg/resources/role_grants_test.go @@ -81,7 +81,6 @@ func TestRoleGrantsDelete(t *testing.T) { }) WithMockDb(t, func(db *sql.DB, mock sqlmock.Sqlmock) { - mock.ExpectExec(`REVOKE ROLE "drop_it" FROM ROLE "role1"`).WillReturnResult(sqlmock.NewResult(1, 1)) mock.ExpectExec(`REVOKE ROLE "drop_it" FROM ROLE "role2"`).WillReturnResult(sqlmock.NewResult(1, 1)) mock.ExpectExec(`REVOKE ROLE "drop_it" FROM USER "user1"`).WillReturnResult(sqlmock.NewResult(1, 1)) diff --git a/pkg/resources/role_ownership_grant_test.go b/pkg/resources/role_ownership_grant_test.go index cbe180d7a6..e413fdcf90 100644 --- a/pkg/resources/role_ownership_grant_test.go +++ b/pkg/resources/role_ownership_grant_test.go @@ -76,7 +76,6 @@ func TestRoleOwnershipGrantDelete(t *testing.T) { }) WithMockDb(t, func(db *sql.DB, mock sqlmock.Sqlmock) { - mock.ExpectExec(`GRANT OWNERSHIP ON ROLE "good_name" TO ROLE "ACCOUNTADMIN" COPY CURRENT GRANTS`).WillReturnResult(sqlmock.NewResult(1, 1)) err := resources.DeleteRoleOwnershipGrant(d, db) r.NoError(err) diff --git a/pkg/resources/schema_grant_acceptance_test.go b/pkg/resources/schema_grant_acceptance_test.go index 23b4b761ec..70c5f94cca 100644 --- a/pkg/resources/schema_grant_acceptance_test.go +++ b/pkg/resources/schema_grant_acceptance_test.go @@ -49,7 +49,6 @@ func TestAcc_SchemaGrant(t *testing.T) { } func TestAcc_SchemaFutureGrants(t *testing.T) { - sName := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha)) roleNameTable := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha)) roleNameView := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha)) diff --git a/pkg/resources/schema_grant_test.go b/pkg/resources/schema_grant_test.go index 2844c4138f..5b5476c4ee 100644 --- a/pkg/resources/schema_grant_test.go +++ b/pkg/resources/schema_grant_test.go @@ -24,6 +24,7 @@ func TestSchemaGrantCreate(t *testing.T) { r := require.New(t) for _, testPriv := range []string{"USAGE", "MODIFY", "CREATE TAG"} { + testPriv := testPriv in := map[string]interface{}{ "schema_name": "test-schema", "database_name": "test-db", diff --git a/pkg/resources/stage_grant_acceptance_test.go b/pkg/resources/stage_grant_acceptance_test.go index 7627820e0b..957c0d2834 100644 --- a/pkg/resources/stage_grant_acceptance_test.go +++ b/pkg/resources/stage_grant_acceptance_test.go @@ -28,7 +28,7 @@ func TestAcc_StageGrant_defaults(t *testing.T) { resource.TestCheckResourceAttr("snowflake_role.r", "name", name), resource.TestCheckResourceAttr("snowflake_stage_grant.g", "database_name", name), resource.TestCheckResourceAttr("snowflake_stage_grant.g", "schema_name", name), - testRolesAndShares(t, "snowflake_stage_grant.g", []string{name}, []string{}), + testRolesAndShares(t, "snowflake_stage_grant.g", []string{name}), ), }, // IMPORT diff --git a/pkg/resources/stage_grant_test.go b/pkg/resources/stage_grant_test.go index 907bb924f4..5a87ef30c9 100644 --- a/pkg/resources/stage_grant_test.go +++ b/pkg/resources/stage_grant_test.go @@ -24,6 +24,7 @@ func TestStageGrantCreate(t *testing.T) { r := require.New(t) for _, testPriv := range []string{"USAGE", "READ"} { + testPriv := testPriv in := map[string]interface{}{ "stage_name": "test-stage", "schema_name": "test-schema", diff --git a/pkg/resources/table.go b/pkg/resources/table.go index b662693d8d..fb4f75ca7c 100644 --- a/pkg/resources/table.go +++ b/pkg/resources/table.go @@ -297,7 +297,6 @@ type columnIdentity struct { func (identity *columnIdentity) toSnowflakeColumnIdentity() *snowflake.ColumnIdentity { snowIdentity := snowflake.ColumnIdentity{} return snowIdentity.WithStartNum(identity.startNum).WithStep(identity.stepNum) - } type column struct { @@ -412,7 +411,6 @@ func getColumnDefault(def map[string]interface{}) *columnDefault { func getColumnIdentity(identity map[string]interface{}) *columnIdentity { if len(identity) > 0 { - startNum := identity["start_num"].(int) stepNum := identity["step_num"].(int) return &columnIdentity{startNum, stepNum} @@ -476,7 +474,6 @@ func getPrimaryKey(from interface{}) (to primarykey) { func (pk primarykey) toSnowflakePrimaryKey() snowflake.PrimaryKey { snowPk := snowflake.PrimaryKey{} return *snowPk.WithName(pk.name).WithKeys(pk.keys) - } // CreateTable implements schema.CreateFunc. @@ -682,22 +679,18 @@ func UpdateTable(d *schema.ResourceData, meta interface{}) error { } } for _, cA := range changed { - if cA.changedDataType { q := builder.ChangeColumnType(cA.newColumn.name, cA.newColumn.dataType) err := snowflake.Exec(db, q) if err != nil { return errors.Wrapf(err, "error changing property on %v", d.Id()) - } } if cA.changedNullConstraint { - q := builder.ChangeNullConstraint(cA.newColumn.name, cA.newColumn.nullable) err := snowflake.Exec(db, q) if err != nil { return errors.Wrapf(err, "error changing property on %v", d.Id()) - } } if cA.dropedDefault { @@ -705,7 +698,6 @@ func UpdateTable(d *schema.ResourceData, meta interface{}) error { err := snowflake.Exec(db, q) if err != nil { return errors.Wrapf(err, "error changing property on %v", d.Id()) - } } if cA.changedComment { @@ -713,7 +705,6 @@ func UpdateTable(d *schema.ResourceData, meta interface{}) error { err := snowflake.Exec(db, q) if err != nil { return errors.Wrapf(err, "error changing property on %v", d.Id()) - } } if cA.changedMaskingPolicy { @@ -721,7 +712,6 @@ func UpdateTable(d *schema.ResourceData, meta interface{}) error { err := snowflake.Exec(db, q) if err != nil { return errors.Wrapf(err, "error changing property on %v", d.Id()) - } } } diff --git a/pkg/resources/table_grant_acceptance_test.go b/pkg/resources/table_grant_acceptance_test.go index 6ebf09ca1f..8fae6ff6d7 100644 --- a/pkg/resources/table_grant_acceptance_test.go +++ b/pkg/resources/table_grant_acceptance_test.go @@ -27,7 +27,7 @@ func TestAccTableGrant_defaults(t *testing.T) { resource.TestCheckResourceAttr("snowflake_table_grant.g", "schema_name", name), resource.TestCheckResourceAttr("snowflake_table_grant.g", "table_name", name), resource.TestCheckResourceAttr("snowflake_table_grant.g", "privilege", "SELECT"), - testRolesAndShares(t, "snowflake_table_grant.g", []string{name}, []string{}), + testRolesAndShares(t, "snowflake_table_grant.g", []string{name}), ), }, // IMPORT diff --git a/pkg/resources/tag_association.go b/pkg/resources/tag_association.go index 282dfbdb95..e1949a6a83 100644 --- a/pkg/resources/tag_association.go +++ b/pkg/resources/tag_association.go @@ -1,10 +1,13 @@ package resources import ( + "context" "database/sql" + "fmt" "log" "time" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" @@ -22,7 +25,7 @@ var tagAssociationSchema = map[string]*schema.Schema{ Deprecated: "Use `object_identifier` instead", ForceNew: true, }, - "object_identifier": &schema.Schema{ + "object_identifier": { Type: schema.TypeList, Required: true, MinItems: 1, @@ -116,9 +119,26 @@ func CreateTagAssociation(d *schema.ResourceData, meta interface{}) error { return errors.Wrapf(err, "error associating tag to object: [%v] with command: [%v], tag_id [%v]", objectIdentifier, q, tagID) } - _, err = snowflake.ListTagAssociations(builder, db) - if err != nil { - return errors.Wrap(err, "error validating tag association") + skipValidate := d.Get("skip_validation").(bool) + if !skipValidate { + log.Println("[DEBUG] validating tag creation") + + err = resource.RetryContext(context.Background(), d.Timeout(schema.TimeoutCreate)-time.Minute, func() *resource.RetryError { + resp, err := snowflake.ListTagAssociations(builder, db) + + if err != nil { + return resource.NonRetryableError(fmt.Errorf("error: %s", err)) + } + + // if length of response is zero, tag association was not found. retry for up to 70 minutes + if len(resp) == 0 { + return resource.RetryableError(fmt.Errorf("expected tag association to be created but not yet created")) + } + return nil + }) + if err != nil { + return errors.Wrap(err, "error validating tag association") + } } t := &TagID{ @@ -131,7 +151,6 @@ func CreateTagAssociation(d *schema.ResourceData, meta interface{}) error { return errors.Wrap(err, "error creating tag id") } d.SetId(dataIDInput) - return ReadTagAssociation(d, meta) } diff --git a/pkg/resources/tag_grant.go b/pkg/resources/tag_grant.go index b6a495d485..90dac2997b 100644 --- a/pkg/resources/tag_grant.go +++ b/pkg/resources/tag_grant.go @@ -193,7 +193,6 @@ func UpdateTagGrant(d *schema.ResourceData, meta interface{}) error { } return ReadTagGrant(d, meta) - } // DeleteTagGrant implements schema.DeleteFunc. diff --git a/pkg/resources/task.go b/pkg/resources/task.go index 93631303f7..924db3c460 100644 --- a/pkg/resources/task.go +++ b/pkg/resources/task.go @@ -427,7 +427,6 @@ func ReadTask(d *schema.ResourceData, meta interface{}) error { return err } } - } return nil @@ -435,7 +434,6 @@ func ReadTask(d *schema.ResourceData, meta interface{}) error { // CreateTask implements schema.CreateFunc. func CreateTask(d *schema.ResourceData, meta interface{}) error { - var err error db := meta.(*sql.DB) database := d.Get("database").(string) @@ -567,7 +565,6 @@ func UpdateTask(d *schema.ResourceData, meta interface{}) error { return errors.Wrapf(err, "error updating user_task_managed_initial_warehouse_size on task %v", d.Id()) } } - } if d.HasChange("error_integration") { diff --git a/pkg/resources/task_internal_test.go b/pkg/resources/task_internal_test.go index 9d6319e637..76cc7f4ea3 100644 --- a/pkg/resources/task_internal_test.go +++ b/pkg/resources/task_internal_test.go @@ -44,5 +44,4 @@ func TestTaskIDFromString(t *testing.T) { database|schema|task` _, err = taskIDFromString(id) r.Equal(fmt.Errorf("1 line per task"), err) - } diff --git a/pkg/resources/user_ownership_grant_test.go b/pkg/resources/user_ownership_grant_test.go index e80b94271d..19782a0a04 100644 --- a/pkg/resources/user_ownership_grant_test.go +++ b/pkg/resources/user_ownership_grant_test.go @@ -92,7 +92,6 @@ func TestUserOwnershipGrantDelete(t *testing.T) { }) WithMockDb(t, func(db *sql.DB, mock sqlmock.Sqlmock) { - mock.ExpectExec(`GRANT OWNERSHIP ON USER "user1" TO ROLE "ACCOUNTADMIN" COPY CURRENT GRANTS`).WillReturnResult(sqlmock.NewResult(1, 1)) err := resources.DeleteUserOwnershipGrant(d, db) r.NoError(err) diff --git a/pkg/resources/user_public_keys.go b/pkg/resources/user_public_keys.go index 8792e07d81..808d438d20 100644 --- a/pkg/resources/user_public_keys.go +++ b/pkg/resources/user_public_keys.go @@ -15,7 +15,7 @@ var userPublicKeyProperties = []string{ "rsa_public_key_2", } -// sanitize input to supress diffs, etc. +// sanitize input to suppress diffs, etc. func publicKeyStateFunc(v interface{}) string { value := v.(string) value = strings.TrimSuffix(value, "\n") diff --git a/pkg/resources/view_grant_acceptance_test.go b/pkg/resources/view_grant_acceptance_test.go index 2fbd4571dd..1fe3e0bbb7 100644 --- a/pkg/resources/view_grant_acceptance_test.go +++ b/pkg/resources/view_grant_acceptance_test.go @@ -32,7 +32,6 @@ func TestAcc_ViewGrantBasic(t *testing.T) { } func TestAcc_ViewGrantShares(t *testing.T) { - databaseName := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha)) viewName := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha)) roleName := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha)) diff --git a/pkg/resources/view_test.go b/pkg/resources/view_test.go index eb0b5763b1..815a728af2 100644 --- a/pkg/resources/view_test.go +++ b/pkg/resources/view_test.go @@ -119,6 +119,7 @@ func TestDiffSuppressStatement(t *testing.T) { {"view 2", args{"", testhelpers.MustFixture(t, "view_2a.sql"), testhelpers.MustFixture(t, "view_2b.sql"), nil}, true}, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { if got := resources.DiffSuppressStatement(tt.args.k, tt.args.old, tt.args.new, tt.args.d); got != tt.want { t.Errorf("DiffSuppressStatement() = %v, want %v", got, tt.want) diff --git a/pkg/snowflake/current_account_test.go b/pkg/snowflake/current_account_test.go index df6b5d7b4f..0273157f21 100644 --- a/pkg/snowflake/current_account_test.go +++ b/pkg/snowflake/current_account_test.go @@ -49,7 +49,8 @@ func TestCurrentAccountRead(t *testing.T) { }, } - for name, testCase := range testCases { + for name, tc := range testCases { + tc := tc t.Run(name, func(t *testing.T) { r := require.New(t) mockDB, mock, err := sqlmock.New() @@ -57,16 +58,16 @@ func TestCurrentAccountRead(t *testing.T) { defer mockDB.Close() sqlxDB := sqlx.NewDb(mockDB, "sqlmock") - rows := sqlmock.NewRows([]string{"account", "region"}).AddRow(testCase.account, testCase.region) + rows := sqlmock.NewRows([]string{"account", "region"}).AddRow(tc.account, tc.region) mock.ExpectQuery(`SELECT CURRENT_ACCOUNT\(\) AS "account", CURRENT_REGION\(\) AS "region";`).WillReturnRows(rows) acc, err := snowflake.ReadCurrentAccount(sqlxDB.DB) r.NoError(err) - r.Equal(testCase.account, acc.Account) - r.Equal(testCase.region, acc.Region) + r.Equal(tc.account, acc.Account) + r.Equal(tc.region, acc.Region) url, err := acc.AccountURL() r.NoError(err) - r.Equal(testCase.url, url) + r.Equal(tc.url, url) }) } } diff --git a/pkg/snowflake/database.go b/pkg/snowflake/database.go index d215bb00be..a6b16ba859 100644 --- a/pkg/snowflake/database.go +++ b/pkg/snowflake/database.go @@ -302,6 +302,7 @@ func ListDatabase(sdb *sqlx.DB, databaseName string) (*database, error) { } db := &database{} for _, d := range dbs { + d := d if d.DBName.String == databaseName { db = &d break diff --git a/pkg/snowflake/escaping_test.go b/pkg/snowflake/escaping_test.go index 142ff0ceba..93ad9d31e2 100644 --- a/pkg/snowflake/escaping_test.go +++ b/pkg/snowflake/escaping_test.go @@ -57,10 +57,11 @@ func TestAddressEscape(t *testing.T) { }, } - for _, testCase := range testCases { - t.Run(testCase.id, func(t *testing.T) { + for _, tc := range testCases { + tc := tc + t.Run(tc.id, func(t *testing.T) { r := require.New(t) - r.Equal(testCase.expected, snowflake.AddressEscape(testCase.name...)) + r.Equal(tc.expected, snowflake.AddressEscape(tc.name...)) }) } } diff --git a/pkg/snowflake/failover_group.go b/pkg/snowflake/failover_group.go index e8e7d4784a..5102badaa1 100644 --- a/pkg/snowflake/failover_group.go +++ b/pkg/snowflake/failover_group.go @@ -216,7 +216,7 @@ func (b *FailoverGroupBuilder) Drop() string { return fmt.Sprintf(`DROP FAILOVER GROUP %v`, b.name) } -// Show returns the SQL query that will show a failover group +// Show returns the SQL query that will show a failover group. func (b *FailoverGroupBuilder) Show() string { return "SHOW FAILOVER GROUPS" } diff --git a/pkg/snowflake/file_format.go b/pkg/snowflake/file_format.go index 481ee0ba64..d57b94b92f 100644 --- a/pkg/snowflake/file_format.go +++ b/pkg/snowflake/file_format.go @@ -240,7 +240,7 @@ func (ffb *FileFormatBuilder) WithDisableSnowflakeData(n bool) *FileFormatBuilde return ffb } -// WithDisableAutoConvert adds disbale auto convert to the FileFormatBuilder. +// WithDisableAutoConvert adds disable auto convert to the FileFormatBuilder. func (ffb *FileFormatBuilder) WithDisableAutoConvert(n bool) *FileFormatBuilder { ffb.disableAutoConvert = n return ffb diff --git a/pkg/snowflake/grant_test.go b/pkg/snowflake/grant_test.go index 0305fc3ad4..9de8f65283 100644 --- a/pkg/snowflake/grant_test.go +++ b/pkg/snowflake/grant_test.go @@ -242,7 +242,6 @@ func TestWarehouseGrant(t *testing.T) { revoke = wg.Role("bob").Revoke("OWNERSHIP") r.Equal([]string{`SET currentRole=CURRENT_ROLE()`, `GRANT OWNERSHIP ON WAREHOUSE "test_warehouse" TO ROLE IDENTIFIER($currentRole) COPY CURRENT GRANTS`}, revoke) - } // lintignore:AT003 diff --git a/pkg/snowflake/parser_test.go b/pkg/snowflake/parser_test.go index a7fef9fcf0..4a17f6bc5f 100644 --- a/pkg/snowflake/parser_test.go +++ b/pkg/snowflake/parser_test.go @@ -55,6 +55,7 @@ from bar;` {"full", args{full}, "SELECT ROLE_NAME, ROLE_OWNER FROM INFORMATION_SCHEMA.APPLICABLE_ROLES", false}, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { e := NewViewSelectStatementExtractor(tt.args.input) got, err := e.Extract() @@ -119,6 +120,7 @@ from bar;` {"full", args{full}, "SELECT ROLE_NAME, ROLE_OWNER FROM INFORMATION_SCHEMA.APPLICABLE_ROLES", false}, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { e := NewViewSelectStatementExtractor(tt.args.input) got, err := e.ExtractMaterializedView() @@ -152,6 +154,7 @@ func TestViewSelectStatementExtractor_consumeToken(t *testing.T) { {"basic - not found", fields{[]rune("fob"), 0}, args{"foo"}, 0}, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { e := &ViewSelectStatementExtractor{ input: tt.fields.input, @@ -181,6 +184,7 @@ func TestViewSelectStatementExtractor_consumeSpace(t *testing.T) { {"middle", fields{[]rune("foo \t\n bar"), 3}, 7}, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { fmt.Println(tt.name) e := &ViewSelectStatementExtractor{ @@ -210,6 +214,7 @@ func TestViewSelectStatementExtractor_consumeComment(t *testing.T) { {"escaped", fields{[]rune(`comment='fo\'o'`), 0}, 15}, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { e := &ViewSelectStatementExtractor{ input: tt.fields.input, @@ -239,6 +244,7 @@ func TestViewSelectStatementExtractor_consumeClusterBy(t *testing.T) { {"double", fields{[]rune("(c1, c2)"), 0}, 8}, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { e := &ViewSelectStatementExtractor{ input: tt.fields.input, diff --git a/pkg/snowflake/pipe_test.go b/pkg/snowflake/pipe_test.go index e19a02050e..0dd9dc9246 100644 --- a/pkg/snowflake/pipe_test.go +++ b/pkg/snowflake/pipe_test.go @@ -27,7 +27,6 @@ func TestPipeCreate(t *testing.T) { s.WithIntegration("myintegration") r.Equal(s.Create(), `CREATE PIPE "test_db"."test_schema"."test_pipe" AUTO_INGEST = TRUE INTEGRATION = 'myintegration' AWS_SNS_TOPIC = 'arn:aws:sns:us-east-1:1234567890123456:mytopic' COMMENT = 'Yeehaw' AS test copy statement `) - } func TestPipeChangeComment(t *testing.T) { diff --git a/pkg/snowflake/replication.go b/pkg/snowflake/replication.go index 0f890a3731..c31cc4b787 100644 --- a/pkg/snowflake/replication.go +++ b/pkg/snowflake/replication.go @@ -40,11 +40,11 @@ type replication struct { AccountLocator sql.NullString `db:"account_locator"` } -func ScanReplication(rows *sqlx.Rows, AccName string) (*replication, error) { +func ScanReplication(rows *sqlx.Rows, accName string) (*replication, error) { for rows.Next() { r := &replication{} err := rows.StructScan(r) - if r.AccountName.String == AccName { + if r.AccountName.String == accName { return r, err } } diff --git a/pkg/snowflake/role_grant_test.go b/pkg/snowflake/role_grant_test.go index 87d1baec9b..4488ff1c9c 100644 --- a/pkg/snowflake/role_grant_test.go +++ b/pkg/snowflake/role_grant_test.go @@ -22,5 +22,4 @@ func TestRoleGrant(t *testing.T) { r2 := rg.Role("role2").Revoke() r.Equal(`REVOKE ROLE "role1" FROM ROLE "role2"`, r2) - } diff --git a/pkg/snowflake/stage.go b/pkg/snowflake/stage.go index fb56a6f6f6..0a5941f200 100644 --- a/pkg/snowflake/stage.go +++ b/pkg/snowflake/stage.go @@ -275,7 +275,6 @@ func DescStage(db *sql.DB, query string) (*descStageResult, error) { defer rows.Close() for rows.Next() { - row := &descStageRow{} if err := rows.StructScan(row); err != nil { return r, err diff --git a/pkg/snowflake/table.go b/pkg/snowflake/table.go index eafc855405..326c4c1007 100644 --- a/pkg/snowflake/table.go +++ b/pkg/snowflake/table.go @@ -51,7 +51,6 @@ type ColumnIdentity struct { func (id *ColumnIdentity) WithStartNum(start int) *ColumnIdentity { id.startNum = start return id - } func (id *ColumnIdentity) WithStep(step int) *ColumnIdentity { @@ -159,7 +158,6 @@ func (c *Column) WithIdentity(id *ColumnIdentity) *Column { } func (c *Column) getColumnDefinition(withInlineConstraints bool, withComment bool) string { - if c == nil { return "" } @@ -189,7 +187,6 @@ func (c *Column) getColumnDefinition(withInlineConstraints bool, withComment boo } return colDef.String() - } func FlattenTablePrimaryKey(pkds []primaryKeyDescription) []interface{} { @@ -222,14 +219,12 @@ func FlattenTablePrimaryKey(pkds []primaryKeyDescription) []interface{} { } keys = append(keys, pk.ColumnName.String) - } flat["name"] = name flat["keys"] = keys flattened = append(flattened, flat) return flattened - } type Columns []Column @@ -395,7 +390,6 @@ func (tb *TableBuilder) UnsetTag(tag TagValue) string { // Function to get clustering definition. func (tb *TableBuilder) GetClusterKeyString() string { - return JoinStringList(tb.clusterBy[:], ", ") } @@ -415,9 +409,7 @@ func (tb *TableBuilder) GetTagValueString() string { } func JoinStringList(instrings []string, delimiter string) string { - return fmt.Sprint(strings.Join(instrings[:], delimiter)) - } func quoteStringList(instrings []string) []string { @@ -425,10 +417,8 @@ func quoteStringList(instrings []string) []string { for _, word := range instrings { quoted := fmt.Sprintf(`"%s"`, word) clean = append(clean, quoted) - } return clean - } func (tb *TableBuilder) getCreateStatementBody() string { @@ -441,7 +431,6 @@ func (tb *TableBuilder) getCreateStatementBody() string { q.WriteString(colDef) if tb.primaryKey.name != "" { q.WriteString(fmt.Sprintf(` ,CONSTRAINT "%v" PRIMARY KEY(%v)`, tb.primaryKey.name, JoinStringList(quoteStringList(tb.primaryKey.keys), ","))) - } else { q.WriteString(fmt.Sprintf(` ,PRIMARY KEY(%v)`, JoinStringList(quoteStringList(tb.primaryKey.keys), ","))) } @@ -470,7 +459,6 @@ func ClusterStatementToList(clusterStatement string) []string { } return clean - } // Table returns a pointer to a Builder that abstracts the DDL operations for a table. @@ -517,7 +505,6 @@ func (tb *TableBuilder) Create() string { if tb.clusterBy != nil { //add optional clustering statement q.WriteString(fmt.Sprintf(` CLUSTER BY LINEAR(%v)`, tb.GetClusterKeyString())) - } q.WriteString(fmt.Sprintf(` DATA_RETENTION_TIME_IN_DAYS = %d`, tb.dataRetentionTimeInDays)) @@ -725,13 +712,11 @@ func (td *tableDescription) ColumnIdentity() *ColumnIdentity { return nil } if strings.Contains(td.Default.String, "IDENTITY") { - split := strings.Split(td.Default.String, " ") start, _ := strconv.Atoi(split[2]) step, _ := strconv.Atoi(split[4]) return &ColumnIdentity{start, step} - } return nil } diff --git a/pkg/snowflake/table_constraint.go b/pkg/snowflake/table_constraint.go index 7430910de1..2b798cf330 100644 --- a/pkg/snowflake/table_constraint.go +++ b/pkg/snowflake/table_constraint.go @@ -183,7 +183,6 @@ func (b *TableConstraintBuilder) Create() string { } return q.String() - } // Rename returns the SQL query that will rename the table constraint. diff --git a/pkg/snowflake/task.go b/pkg/snowflake/task.go index 4ccdfdd37a..afbcd2bdba 100644 --- a/pkg/snowflake/task.go +++ b/pkg/snowflake/task.go @@ -433,7 +433,6 @@ func ScanTaskParameters(rows *sqlx.Rows) ([]*taskParams, error) { return nil, err } t = append(t, r) - } return t, nil } diff --git a/pkg/snowflake/validation.go b/pkg/snowflake/validation.go index 3de1ef2a94..2d9626ff74 100644 --- a/pkg/snowflake/validation.go +++ b/pkg/snowflake/validation.go @@ -37,7 +37,6 @@ func ValidateIdentifier(val interface{}, exclusions []string) (warns []string, e } } return - } func isIdentifierRune(r rune, excludedCharacters map[string]bool) bool { diff --git a/pkg/snowflake/validation_test.go b/pkg/snowflake/validation_test.go index e56297309a..431425d90e 100644 --- a/pkg/snowflake/validation_test.go +++ b/pkg/snowflake/validation_test.go @@ -23,6 +23,7 @@ func TestValidateIdentifier(t *testing.T) { } for _, tc := range cases { + tc := tc t.Run(tc.candidate, func(t *testing.T) { _, errs := snowflake.ValidateIdentifier(tc.candidate, []string{}) actual := len(errs) == 0 diff --git a/pkg/testhelpers/helpers.go b/pkg/testhelpers/helpers.go index 50a0270b29..298658a63c 100644 --- a/pkg/testhelpers/helpers.go +++ b/pkg/testhelpers/helpers.go @@ -22,5 +22,4 @@ func WithMockDb(t *testing.T, f func(*sql.DB, sqlmock.Sqlmock)) { if err := mock.ExpectationsWereMet(); err != nil { t.Errorf("there were unfulfilled expectations: %s", err) } - }