Skip to content

Commit

Permalink
Prove #2679 permadiff
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-asawicki committed Oct 10, 2024
1 parent 521559c commit 92afd57
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 4 deletions.
7 changes: 7 additions & 0 deletions pkg/acceptance/helpers/stage_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,10 @@ func (c *StageClient) Rename(t *testing.T, id sdk.SchemaObjectIdentifier, newId
err := c.client().Alter(ctx, sdk.NewAlterStageRequest(id).WithRenameTo(&newId))
require.NoError(t, err)
}

func (c *StageClient) Describe(t *testing.T, id sdk.SchemaObjectIdentifier) ([]sdk.StageProperty, error) {
t.Helper()
ctx := context.Background()

return c.client().Describe(ctx, id)
}
81 changes: 80 additions & 1 deletion pkg/resources/stage_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@ import (
"testing"

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

"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random"
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/ids"
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/testenvs"
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/collections"
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/provider/resources"
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk"
"github.com/hashicorp/terraform-plugin-testing/config"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/plancheck"
"github.com/hashicorp/terraform-plugin-testing/terraform"
"github.com/hashicorp/terraform-plugin-testing/tfversion"
)

Expand Down Expand Up @@ -255,3 +257,80 @@ resource "snowflake_stage" "test" {
}
`, stageId.Name(), stageId.DatabaseName(), stageId.SchemaName())
}

// TODO [SNOW-1348110]: fix behavior with stage rework
func TestAcc_Stage_Issue2679(t *testing.T) {
integrationId := acc.TestClient().Ids.RandomAccountObjectIdentifier()
stageId := acc.TestClient().Ids.RandomSchemaObjectIdentifier()
resourceName := "snowflake_stage.test"

fileFormatWithDefaultTypeCsv := "TYPE = CSV NULL_IF = []"
fileFormatWithoutType := "NULL_IF = []"

resource.Test(t, resource.TestCase{
ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories,
PreCheck: func() { acc.TestAccPreCheck(t) },
TerraformVersionChecks: []tfversion.TerraformVersionCheck{
tfversion.RequireAbove(tfversion.Version1_5_0),
},
CheckDestroy: acc.CheckDestroy(t, resources.Stage),
Steps: []resource.TestStep{
{
Config: stageIssue2679Config(integrationId, stageId, fileFormatWithDefaultTypeCsv),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "name", stageId.Name()),
),
ExpectNonEmptyPlan: true,
},
{
ConfigPlanChecks: resource.ConfigPlanChecks{
PreApply: []plancheck.PlanCheck{
plancheck.ExpectEmptyPlan(),
},
},
Config: stageIssue2679Config(integrationId, stageId, fileFormatWithoutType),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "name", stageId.Name()),
// TODO [SNOW-1348110]: use generated assertions after stage rework
func(_ *terraform.State) error {
properties, err := acc.TestClient().Stage.Describe(t, stageId)
if err != nil {
return err
}
typeProperty, err := collections.FindFirst(properties, func(property sdk.StageProperty) bool {
return property.Parent == "STAGE_FILE_FORMAT" && property.Name == "TYPE"
})
if err != nil {
return err
}
if typeProperty.Value != "CSV" {
return fmt.Errorf("expected type property 'CSV', got '%s'", typeProperty.Value)
}
return nil
},
),
},
},
})
}

func stageIssue2679Config(integrationId sdk.AccountObjectIdentifier, stageId sdk.SchemaObjectIdentifier, fileFormat string) string {
return fmt.Sprintf(`
resource "snowflake_storage_integration" "test" {
name = "%[1]s"
storage_allowed_locations = ["s3://aaaaa"]
storage_provider = "S3"
storage_aws_role_arn = "arn:aws:iam::000000000001:/role/test"
}
resource "snowflake_stage" "test" {
name = "%[2]s"
database = "%[3]s"
schema = "%[4]s"
file_format = "%[5]s"
storage_integration = snowflake_storage_integration.test.name
url = "s3://aaaaa"
}
`, integrationId.Name(), stageId.Name(), stageId.DatabaseName(), stageId.SchemaName(), fileFormat)
}
Loading

0 comments on commit 92afd57

Please sign in to comment.