Skip to content

Commit

Permalink
Differentiating between external and internal stage in testing (#427)
Browse files Browse the repository at this point in the history
When working on this PR: #426
I found that external stage and internal stage are slightly different, and should be tested.

Tests fail until the referenced PR is merged.
  • Loading branch information
alldoami authored Jan 26, 2021
1 parent de9974c commit f3ef140
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 4 deletions.
52 changes: 52 additions & 0 deletions pkg/resources/external_stage_acceptance_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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"
Expand Down
27 changes: 26 additions & 1 deletion pkg/resources/stage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}{
Expand All @@ -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"},
Expand Down

0 comments on commit f3ef140

Please sign in to comment.