Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Differentiating between external and internal stage in testing #427

Merged
merged 6 commits into from
Jan 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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{
ryanking marked this conversation as resolved.
Show resolved Hide resolved
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