From c2750237ecd28e056b49e11a9e7754fc1d7eb9e3 Mon Sep 17 00:00:00 2001 From: adoami Date: Thu, 21 Jan 2021 17:30:42 -0800 Subject: [PATCH 1/4] Differentiating between external and internal stage in testing --- .../external_stage_acceptance_test.go | 53 +++++++++++++++++++ ...t.go => internal_stage_acceptance_test.go} | 6 +-- 2 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 pkg/resources/external_stage_acceptance_test.go rename pkg/resources/{stage_acceptance_test.go => internal_stage_acceptance_test.go} (90%) diff --git a/pkg/resources/external_stage_acceptance_test.go b/pkg/resources/external_stage_acceptance_test.go new file mode 100644 index 0000000000..1af9f65cdd --- /dev/null +++ b/pkg/resources/external_stage_acceptance_test.go @@ -0,0 +1,53 @@ +package resources_test + +import ( + "fmt" + "strings" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAcc_ExternalStage(t *testing.T) { + accName := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha)) + + resource.ParallelTest(t, resource.TestCase{ + Providers: providers(), + Steps: []resource.TestStep{ + { + Config: externalStageConfig(accName), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("snowflake_stage.test", "name", accName), + resource.TestCheckResourceAttr("snowflake_stage.test", "database", accName), + resource.TestCheckResourceAttr("snowflake_stage.test", "schema", accName), + resource.TestCheckResourceAttr("snowflake_stage.test", "comment", "Terraform acceptance test"), + ), + }, + }, + }) +} + +// The defining feature of an external stage is the url that you provide when creating the stage +func externalStageConfig(n string) string { + return fmt.Sprintf(` +resource "snowflake_database" "test" { + name = "%v" + comment = "Terraform acceptance test" +} + +resource "snowflake_schema" "test" { + name = "%v" + database = snowflake_database.test.name + comment = "Terraform acceptance test" +} + +resource "snowflake_stage" "test" { + name = "%v" + url = "s3://com.example.bucket/prefix" + database = snowflake_database.test.name + schema = snowflake_schema.test.name + comment = "Terraform acceptance test" +} +`, n, n, n) +} diff --git a/pkg/resources/stage_acceptance_test.go b/pkg/resources/internal_stage_acceptance_test.go similarity index 90% rename from pkg/resources/stage_acceptance_test.go rename to pkg/resources/internal_stage_acceptance_test.go index be3591caf9..192a463306 100644 --- a/pkg/resources/stage_acceptance_test.go +++ b/pkg/resources/internal_stage_acceptance_test.go @@ -9,14 +9,14 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) -func TestAcc_Stage(t *testing.T) { +func TestAcc_InteralStage(t *testing.T) { accName := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha)) resource.ParallelTest(t, resource.TestCase{ Providers: providers(), Steps: []resource.TestStep{ { - Config: stageConfig(accName), + Config: internalStageConfig(accName), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("snowflake_stage.test", "name", accName), resource.TestCheckResourceAttr("snowflake_stage.test", "database", accName), @@ -28,7 +28,7 @@ func TestAcc_Stage(t *testing.T) { }) } -func stageConfig(n string) string { +func internalStageConfig(n string) string { return fmt.Sprintf(` resource "snowflake_database" "test" { name = "%v" From c14453c722f664653c378d6ce3529fa211be0a08 Mon Sep 17 00:00:00 2001 From: adoami Date: Thu, 21 Jan 2021 17:35:31 -0800 Subject: [PATCH 2/4] add new testg --- pkg/resources/stage_test.go | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/pkg/resources/stage_test.go b/pkg/resources/stage_test.go index 05ee297818..5d351aac40 100644 --- a/pkg/resources/stage_test.go +++ b/pkg/resources/stage_test.go @@ -19,7 +19,7 @@ func TestStage(t *testing.T) { r.NoError(err) } -func TestStageCreate(t *testing.T) { +func TestInternalStageCreate(t *testing.T) { r := require.New(t) in := map[string]interface{}{ @@ -43,6 +43,31 @@ func TestStageCreate(t *testing.T) { }) } +func TestExternalStageCreate(t *testing.T) { + r := require.New(t) + + in := map[string]interface{}{ + "name": "test_stage", + "database": "test_db", + "url": "s3://com.example.bucket/prefix", + "schema": "test_schema", + "comment": "great comment", + } + d := schema.TestResourceDataRaw(t, resources.Stage().Schema, in) + r.NotNil(d) + + WithMockDb(t, func(db *sql.DB, mock sqlmock.Sqlmock) { + mock.ExpectExec( + `^CREATE STAGE "test_db"."test_schema"."test_stage" URL = 's3://com.example.bucket/prefix' COMMENT = 'great comment'$`, + ).WillReturnResult(sqlmock.NewResult(1, 1)) + + expectReadStage(mock) + expectReadStageShow(mock) + err := resources.CreateStage(d, db) + r.NoError(err) + }) +} + func expectReadStage(mock sqlmock.Sqlmock) { rows := sqlmock.NewRows([]string{ "parent_property", "property", "property_type", "property_value", "property_default"}, From ddde37f00bc5a140cbac0d67eefeac18567464d8 Mon Sep 17 00:00:00 2001 From: adoami Date: Thu, 21 Jan 2021 17:36:57 -0800 Subject: [PATCH 3/4] remove comment --- pkg/resources/external_stage_acceptance_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/pkg/resources/external_stage_acceptance_test.go b/pkg/resources/external_stage_acceptance_test.go index 1af9f65cdd..711089672b 100644 --- a/pkg/resources/external_stage_acceptance_test.go +++ b/pkg/resources/external_stage_acceptance_test.go @@ -28,7 +28,6 @@ func TestAcc_ExternalStage(t *testing.T) { }) } -// The defining feature of an external stage is the url that you provide when creating the stage func externalStageConfig(n string) string { return fmt.Sprintf(` resource "snowflake_database" "test" { From ee8a9a20cc4dcce5cc057e7683867c311f25441c Mon Sep 17 00:00:00 2001 From: adoami Date: Thu, 21 Jan 2021 17:49:13 -0800 Subject: [PATCH 4/4] spelling --- pkg/resources/internal_stage_acceptance_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/resources/internal_stage_acceptance_test.go b/pkg/resources/internal_stage_acceptance_test.go index 192a463306..390b6793b7 100644 --- a/pkg/resources/internal_stage_acceptance_test.go +++ b/pkg/resources/internal_stage_acceptance_test.go @@ -9,7 +9,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) -func TestAcc_InteralStage(t *testing.T) { +func TestAcc_InternalStage(t *testing.T) { accName := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha)) resource.ParallelTest(t, resource.TestCase{