Skip to content

Commit

Permalink
chore: Fix tests after v1 release (#3306)
Browse files Browse the repository at this point in the history
Fix tests after V1:
- TestAcc_Functions
- TestAcc_Procedures
- TestAcc_ExternalFunction_complete
- TestAcc_GrantOwnership_OnObject_ProcedureWithArguments_ToAccountRole
-
TestAcc_GrantOwnership_OnObject_ProcedureWithoutArguments_ToDatabaseRole
- extended authenticator unit test
- Parameters tests were not altered but the environment was adjusted (to
verify if they will still fail)

Additionally:
- added 3 missing preview features (2 needed for tests and 1 just
missing for completion)
  • Loading branch information
sfc-gh-asawicki committed Dec 20, 2024
1 parent e2d0705 commit 32983fe
Show file tree
Hide file tree
Showing 11 changed files with 119 additions and 161 deletions.
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ provider "snowflake" {
- `passcode_in_password` (Boolean) False by default. Set to true if the MFA passcode is embedded to the configured password. Can also be sourced from the `SNOWFLAKE_PASSCODE_IN_PASSWORD` environment variable.
- `password` (String, Sensitive) Password for user + password auth. Cannot be used with `private_key` and `private_key_passphrase`. Can also be sourced from the `SNOWFLAKE_PASSWORD` environment variable.
- `port` (Number) Specifies a custom port value used by the driver for privatelink connections. Can also be sourced from the `SNOWFLAKE_PORT` environment variable.
- `preview_features_enabled` (Set of String) A list of preview features that are handled by the provider. See [preview features list](https://github.com/Snowflake-Labs/terraform-provider-snowflake/blob/main/v1-preparations/LIST_OF_PREVIEW_FEATURES_FOR_V1.md). Preview features may have breaking changes in future releases, even without raising the major version. This field can not be set with environmental variables. Valid options are: `snowflake_current_account_datasource` | `snowflake_account_authentication_policy_attachment_resource` | `snowflake_account_password_policy_attachment_resource` | `snowflake_alert_resource` | `snowflake_alerts_datasource` | `snowflake_api_integration_resource` | `snowflake_authentication_policy_resource` | `snowflake_cortex_search_service_resource` | `snowflake_cortex_search_services_datasource` | `snowflake_database_datasource` | `snowflake_database_role_datasource` | `snowflake_dynamic_table_resource` | `snowflake_dynamic_tables_datasource` | `snowflake_external_function_resource` | `snowflake_external_functions_datasource` | `snowflake_external_table_resource` | `snowflake_external_tables_datasource` | `snowflake_external_volume_resource` | `snowflake_failover_group_resource` | `snowflake_failover_groups_datasource` | `snowflake_file_format_resource` | `snowflake_file_formats_datasource` | `snowflake_function_java_resource` | `snowflake_function_javascript_resource` | `snowflake_function_python_resource` | `snowflake_function_scala_resource` | `snowflake_function_sql_resource` | `snowflake_managed_account_resource` | `snowflake_materialized_view_resource` | `snowflake_materialized_views_datasource` | `snowflake_network_policy_attachment_resource` | `snowflake_network_rule_resource` | `snowflake_email_notification_integration_resource` | `snowflake_notification_integration_resource` | `snowflake_object_parameter_resource` | `snowflake_password_policy_resource` | `snowflake_pipe_resource` | `snowflake_pipes_datasource` | `snowflake_current_role_datasource` | `snowflake_sequence_resource` | `snowflake_sequences_datasource` | `snowflake_share_resource` | `snowflake_shares_datasource` | `snowflake_parameters_datasource` | `snowflake_procedure_java_resource` | `snowflake_procedure_javascript_resource` | `snowflake_procedure_python_resource` | `snowflake_procedure_scala_resource` | `snowflake_procedure_sql_resource` | `snowflake_stage_resource` | `snowflake_stages_datasource` | `snowflake_storage_integration_resource` | `snowflake_storage_integrations_datasource` | `snowflake_system_generate_scim_access_token_datasource` | `snowflake_system_get_aws_sns_iam_policy_datasource` | `snowflake_system_get_privatelink_config_datasource` | `snowflake_system_get_snowflake_platform_info_datasource` | `snowflake_table_column_masking_policy_application_resource` | `snowflake_table_constraint_resource` | `snowflake_table_resource` | `snowflake_user_authentication_policy_attachment_resource` | `snowflake_user_public_keys_resource` | `snowflake_user_password_policy_attachment_resource`.
- `preview_features_enabled` (Set of String) A list of preview features that are handled by the provider. See [preview features list](https://github.com/Snowflake-Labs/terraform-provider-snowflake/blob/main/v1-preparations/LIST_OF_PREVIEW_FEATURES_FOR_V1.md). Preview features may have breaking changes in future releases, even without raising the major version. This field can not be set with environmental variables. Valid options are: `snowflake_current_account_datasource` | `snowflake_account_authentication_policy_attachment_resource` | `snowflake_account_password_policy_attachment_resource` | `snowflake_alert_resource` | `snowflake_alerts_datasource` | `snowflake_api_integration_resource` | `snowflake_authentication_policy_resource` | `snowflake_cortex_search_service_resource` | `snowflake_cortex_search_services_datasource` | `snowflake_database_datasource` | `snowflake_database_role_datasource` | `snowflake_dynamic_table_resource` | `snowflake_dynamic_tables_datasource` | `snowflake_external_function_resource` | `snowflake_external_functions_datasource` | `snowflake_external_table_resource` | `snowflake_external_tables_datasource` | `snowflake_external_volume_resource` | `snowflake_failover_group_resource` | `snowflake_failover_groups_datasource` | `snowflake_file_format_resource` | `snowflake_file_formats_datasource` | `snowflake_function_java_resource` | `snowflake_function_javascript_resource` | `snowflake_function_python_resource` | `snowflake_function_scala_resource` | `snowflake_function_sql_resource` | `snowflake_functions_datasource` | `snowflake_managed_account_resource` | `snowflake_materialized_view_resource` | `snowflake_materialized_views_datasource` | `snowflake_network_policy_attachment_resource` | `snowflake_network_rule_resource` | `snowflake_email_notification_integration_resource` | `snowflake_notification_integration_resource` | `snowflake_object_parameter_resource` | `snowflake_password_policy_resource` | `snowflake_pipe_resource` | `snowflake_pipes_datasource` | `snowflake_current_role_datasource` | `snowflake_sequence_resource` | `snowflake_sequences_datasource` | `snowflake_share_resource` | `snowflake_shares_datasource` | `snowflake_parameters_datasource` | `snowflake_procedure_java_resource` | `snowflake_procedure_javascript_resource` | `snowflake_procedure_python_resource` | `snowflake_procedure_scala_resource` | `snowflake_procedure_sql_resource` | `snowflake_procedures_datasource` | `snowflake_stage_resource` | `snowflake_stages_datasource` | `snowflake_storage_integration_resource` | `snowflake_storage_integrations_datasource` | `snowflake_system_generate_scim_access_token_datasource` | `snowflake_system_get_aws_sns_iam_policy_datasource` | `snowflake_system_get_privatelink_config_datasource` | `snowflake_system_get_snowflake_platform_info_datasource` | `snowflake_table_column_masking_policy_application_resource` | `snowflake_table_constraint_resource` | `snowflake_table_resource` | `snowflake_tables_datasource` | `snowflake_user_authentication_policy_attachment_resource` | `snowflake_user_public_keys_resource` | `snowflake_user_password_policy_attachment_resource`.
- `private_key` (String, Sensitive) Private Key for username+private-key auth. Cannot be used with `password`. Can also be sourced from the `SNOWFLAKE_PRIVATE_KEY` environment variable.
- `private_key_passphrase` (String, Sensitive) Supports the encryption ciphers aes-128-cbc, aes-128-gcm, aes-192-cbc, aes-192-gcm, aes-256-cbc, aes-256-gcm, and des-ede3-cbc. Can also be sourced from the `SNOWFLAKE_PRIVATE_KEY_PASSPHRASE` environment variable.
- `profile` (String) Sets the profile to read from ~/.snowflake/config file. Can also be sourced from the `SNOWFLAKE_PROFILE` environment variable.
Expand Down
57 changes: 42 additions & 15 deletions pkg/datasources/functions_acceptance_test.go
Original file line number Diff line number Diff line change
@@ -1,40 +1,37 @@
package datasources_test

import (
"fmt"
"testing"

acc "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance"

"github.com/hashicorp/terraform-plugin-testing/config"
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/config"
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/config/model"
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/testdatatypes"
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/testenvs"
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/provider/resources"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/tfversion"
)

func TestAcc_Functions(t *testing.T) {
functionNameOne := acc.TestClient().Ids.Alpha()
functionNameTwo := acc.TestClient().Ids.Alpha()
_ = testenvs.GetOrSkipTest(t, testenvs.EnableAcceptance)
acc.TestAccPreCheck(t)
t.Setenv(string(testenvs.ConfigureClientOnce), "")

dataSourceName := "data.snowflake_functions.functions"

m := func() map[string]config.Variable {
return map[string]config.Variable{
"database": config.StringVariable(acc.TestDatabaseName),
"schema": config.StringVariable(acc.TestSchemaName),
"function_name_one": config.StringVariable(functionNameOne),
"function_name_two": config.StringVariable(functionNameTwo),
}
}
variableSet1 := m()
resource.Test(t, resource.TestCase{
ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories,
PreCheck: func() { acc.TestAccPreCheck(t) },
TerraformVersionChecks: []tfversion.TerraformVersionCheck{
tfversion.RequireAbove(tfversion.Version1_5_0),
},
CheckDestroy: nil,
CheckDestroy: acc.CheckDestroy(t, resources.FunctionJava),
Steps: []resource.TestStep{
{
ConfigDirectory: acc.ConfigurationDirectory("TestAcc_Functions/complete"),
ConfigVariables: variableSet1,
Config: functionsConfig(t),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(dataSourceName, "database", acc.TestDatabaseName),
resource.TestCheckResourceAttr(dataSourceName, "schema", acc.TestSchemaName),
Expand All @@ -44,3 +41,33 @@ func TestAcc_Functions(t *testing.T) {
},
})
}

// TODO [SNOW-1348103]: use generated config builder when reworking the datasource
func functionsConfig(t *testing.T) string {
t.Helper()

className := "TestFunc"
funcName := "echoVarchar"
argName := "x"
dataType := testdatatypes.DataTypeVarchar_100

handler := fmt.Sprintf("%s.%s", className, funcName)
definition := acc.TestClient().Function.SampleJavaDefinition(t, className, funcName, argName)

id1 := acc.TestClient().Ids.RandomSchemaObjectIdentifierWithArgumentsNewDataTypes(dataType)
id2 := acc.TestClient().Ids.RandomSchemaObjectIdentifierWithArgumentsNewDataTypes(dataType)

functionsSetup := config.FromModels(t,
model.FunctionJavaBasicInline("f1", id1, dataType, handler, definition).WithArgument(argName, dataType),
model.FunctionJavaBasicInline("f2", id2, dataType, handler, definition).WithArgument(argName, dataType),
)

return fmt.Sprintf(`
%s
data "snowflake_functions" "functions" {
database = "%s"
schema = "%s"
depends_on = [snowflake_function_java.f1, snowflake_function_java.f2]
}
`, functionsSetup, acc.TestDatabaseName, acc.TestSchemaName)
}
60 changes: 45 additions & 15 deletions pkg/datasources/procedures_acceptance_test.go
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
package datasources_test

import (
"fmt"
"testing"

"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/testenvs"

acc "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance"
"github.com/hashicorp/terraform-plugin-testing/config"

"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/config"
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/config/model"
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/testdatatypes"
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/provider/resources"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/tfversion"
)

func TestAcc_Procedures(t *testing.T) {
procNameOne := acc.TestClient().Ids.Alpha()
procNameTwo := acc.TestClient().Ids.Alpha()
_ = testenvs.GetOrSkipTest(t, testenvs.EnableAcceptance)
acc.TestAccPreCheck(t)
t.Setenv(string(testenvs.ConfigureClientOnce), "")

dataSourceName := "data.snowflake_procedures.procedures"
m := func() map[string]config.Variable {
return map[string]config.Variable{
"database": config.StringVariable(acc.TestDatabaseName),
"schema": config.StringVariable(acc.TestSchemaName),
"proc_name_one": config.StringVariable(procNameOne),
"proc_name_two": config.StringVariable(procNameTwo),
}
}
configVariables := m()

resource.Test(t, resource.TestCase{
ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories,
PreCheck: func() { acc.TestAccPreCheck(t) },
TerraformVersionChecks: []tfversion.TerraformVersionCheck{
tfversion.RequireAbove(tfversion.Version1_5_0),
},
CheckDestroy: nil,
CheckDestroy: acc.CheckDestroy(t, resources.ProcedureJava),
Steps: []resource.TestStep{
{
ConfigDirectory: acc.ConfigurationDirectory("TestAcc_Procedures/complete"),
ConfigVariables: configVariables,
Config: proceduresConfig(t),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(dataSourceName, "database", acc.TestDatabaseName),
resource.TestCheckResourceAttr(dataSourceName, "schema", acc.TestSchemaName),
Expand All @@ -44,3 +44,33 @@ func TestAcc_Procedures(t *testing.T) {
},
})
}

// TODO [SNOW-1348103]: use generated config builder when reworking the datasource
func proceduresConfig(t *testing.T) string {
t.Helper()

className := "TestFunc"
funcName := "echoVarchar"
argName := "x"
dataType := testdatatypes.DataTypeVarchar_100

handler := fmt.Sprintf("%s.%s", className, funcName)
definition := acc.TestClient().Procedure.SampleJavaDefinition(t, className, funcName, argName)

id1 := acc.TestClient().Ids.RandomSchemaObjectIdentifierWithArgumentsNewDataTypes(dataType)
id2 := acc.TestClient().Ids.RandomSchemaObjectIdentifierWithArgumentsNewDataTypes(dataType)

functionsSetup := config.FromModels(t,
model.ProcedureJavaBasicInline("p1", id1, dataType, handler, definition).WithArgument(argName, dataType),
model.ProcedureJavaBasicInline("p2", id2, dataType, handler, definition).WithArgument(argName, dataType),
)

return fmt.Sprintf(`
%s
data "snowflake_procedures" "procedures" {
database = "%s"
schema = "%s"
depends_on = [snowflake_procedure_java.p1, snowflake_procedure_java.p2]
}
`, functionsSetup, acc.TestDatabaseName, acc.TestSchemaName)
}
33 changes: 0 additions & 33 deletions pkg/datasources/testdata/TestAcc_Functions/complete/test.tf

This file was deleted.

15 changes: 0 additions & 15 deletions pkg/datasources/testdata/TestAcc_Functions/complete/variables.tf

This file was deleted.

47 changes: 0 additions & 47 deletions pkg/datasources/testdata/TestAcc_Procedures/complete/test.tf

This file was deleted.

3 changes: 3 additions & 0 deletions pkg/provider/previewfeatures/preview_features.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ var allPreviewFeatures = []feature{
FunctionPythonResource,
FunctionScalaResource,
FunctionSqlResource,
FunctionsDatasource,
ManagedAccountResource,
MaterializedViewResource,
MaterializedViewsDatasource,
Expand All @@ -127,6 +128,7 @@ var allPreviewFeatures = []feature{
ProcedurePythonResource,
ProcedureScalaResource,
ProcedureSqlResource,
ProceduresDatasource,
StageResource,
StagesDatasource,
StorageIntegrationResource,
Expand All @@ -138,6 +140,7 @@ var allPreviewFeatures = []feature{
TableColumnMaskingPolicyApplicationResource,
TableConstraintResource,
TableResource,
TablesDatasource,
UserAuthenticationPolicyAttachmentResource,
UserPublicKeysResource,
UserPasswordPolicyAttachmentResource,
Expand Down
33 changes: 14 additions & 19 deletions pkg/resources/testdata/TestAcc_ExternalFunction/complete/test.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,36 @@ resource "snowflake_api_integration" "test_api_int" {
enabled = true
}

resource "snowflake_function" "test_func_req_translator" {
resource "snowflake_function_javascript" "test_func_req_translator" {
name = "${var.name}_request_translator"
database = var.database
schema = var.schema
arguments {
name = "EVENT"
type = "OBJECT"
arg_name = "EVENT"
arg_data_type = "OBJECT"
}
comment = "Terraform acceptance test"
return_type = "OBJECT"
language = "javascript"
statement = <<EOH
return_type = "OBJECT"
function_definition = <<EOT
let exeprimentName = EVENT.body.data[0][1]
return { "body": { "name": test }}
EOH
EOT
}


resource "snowflake_function" "test_func_res_translator" {
resource "snowflake_function_javascript" "test_func_res_translator" {
name = "${var.name}_response_translator"
database = var.database
schema = var.schema
arguments {
name = "EVENT"
type = "OBJECT"
arg_name = "EVENT"
arg_data_type = "OBJECT"
}
comment = "Terraform acceptance test"
return_type = "OBJECT"
language = "javascript"
statement = <<EOH
return_type = "OBJECT"
function_definition = <<EOT
return { "body": { "data" : [[0, EVENT]] } };
EOH
EOT
}


resource "snowflake_external_function" "external_function" {
name = var.name
database = var.database
Expand All @@ -54,7 +49,7 @@ resource "snowflake_external_function" "external_function" {
value = "snowflake"
}
max_batch_rows = 500
request_translator = "${var.database}.${var.schema}.${snowflake_function.test_func_req_translator.name}"
response_translator = "${var.database}.${var.schema}.${snowflake_function.test_func_res_translator.name}"
request_translator = "${var.database}.${var.schema}.${snowflake_function_javascript.test_func_req_translator.name}"
response_translator = "${var.database}.${var.schema}.${snowflake_function_javascript.test_func_res_translator.name}"
url_of_proxy_and_resource = var.url_of_proxy_and_resource
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@ resource "snowflake_procedure_javascript" "test" {
database = snowflake_database.test.name
schema = snowflake_schema.test.name
arguments {
name = "ARG1"
type = "FLOAT"
arg_name = "ARG1"
arg_data_type = "FLOAT"
}
return_type = "FLOAT"
execute_as = "CALLER"
return_behavior = "VOLATILE"
null_input_behavior = "RETURNS NULL ON NULL INPUT"
statement = <<EOT
return_type = "FLOAT"
execute_as = "CALLER"
null_input_behavior = "RETURNS NULL ON NULL INPUT"
procedure_definition = <<EOT
var X=1
return X
EOT
Expand Down
Loading

0 comments on commit 32983fe

Please sign in to comment.