diff --git a/pkg/resources/external_stage_acceptance_test.go b/pkg/resources/external_stage_acceptance_test.go new file mode 100644 index 0000000000..711089672b --- /dev/null +++ b/pkg/resources/external_stage_acceptance_test.go @@ -0,0 +1,52 @@ +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"), + ), + }, + }, + }) +} + +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..390b6793b7 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_InternalStage(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" 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"},