Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-jcieslak committed Dec 7, 2023
1 parent eba58ad commit 9e0ac28
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 37 deletions.
80 changes: 47 additions & 33 deletions pkg/resources/schema_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,43 +47,57 @@ func TestAcc_Schema(t *testing.T) {
})
}

//func TestAcc_SchemaRename(t *testing.T) {
// oldSchemaName := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha))
// newSchemaName := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha))
//
// resource.ParallelTest(t, resource.TestCase{
// Providers: acc.TestAccProviders(),
// PreCheck: func() { acc.TestAccPreCheck(t) },
// CheckDestroy: nil,
// Steps: []resource.TestStep{
//, {
// Config: schemaConfig(oldSchemaName, acc.TestDatabaseName),
// Check: resource.ComposeTestCheckFunc(
// resource.TestCheckResourceAttr("snowflake_schema.test", "name", oldSchemaName),
// resource.TestCheckResourceAttr("snowflake_schema.test", "database", acc.TestDatabaseName),
// resource.TestCheckResourceAttr("snowflake_schema.test", "comment", "Terraform acceptance test"),
// checkBool("snowflake_schema.test", "is_transient", false), // this is from user_acceptance_test.go
// checkBool("snowflake_schema.test", "is_managed", false),
// ),
// },
// {
// Config: schemaConfig(newSchemaName, acc.TestDatabaseName),
// Check: resource.ComposeTestCheckFunc(
// resource.TestCheckResourceAttr("snowflake_schema.test", "name", newSchemaName),
// resource.TestCheckResourceAttr("snowflake_schema.test", "database", acc.TestDatabaseName),
// resource.TestCheckResourceAttr("snowflake_schema.test", "comment", "Terraform acceptance test"),
// checkBool("snowflake_schema.test", "is_transient", false), // this is from user_acceptance_test.go
// checkBool("snowflake_schema.test", "is_managed", false),
// ),
// },
// },
// })
//}
func TestAcc_Schema_Rename(t *testing.T) {
oldSchemaName := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha))
newSchemaName := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha))
comment := "Terraform acceptance test"

resource.Test(t, resource.TestCase{
ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories,
PreCheck: func() { acc.TestAccPreCheck(t) },
TerraformVersionChecks: []tfversion.TerraformVersionCheck{
tfversion.RequireAbove(tfversion.Version1_5_0),
},
CheckDestroy: testAccCheckSchemaDestroy,
Steps: []resource.TestStep{
{
ConfigDirectory: config.TestNameDirectory(),
ConfigVariables: map[string]config.Variable{
"name": config.StringVariable(oldSchemaName),
"database": config.StringVariable(acc.TestDatabaseName),
"comment": config.StringVariable(comment),
},
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("snowflake_schema.test", "name", oldSchemaName),
resource.TestCheckResourceAttr("snowflake_schema.test", "database", acc.TestDatabaseName),
resource.TestCheckResourceAttr("snowflake_schema.test", "comment", comment),
checkBool("snowflake_schema.test", "is_transient", false),
checkBool("snowflake_schema.test", "is_managed", false),
),
},
{
ConfigDirectory: config.TestNameDirectory(),
ConfigVariables: map[string]config.Variable{
"name": config.StringVariable(newSchemaName),
"database": config.StringVariable(acc.TestDatabaseName),
"comment": config.StringVariable(comment),
},
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("snowflake_schema.test", "name", newSchemaName),
resource.TestCheckResourceAttr("snowflake_schema.test", "database", acc.TestDatabaseName),
resource.TestCheckResourceAttr("snowflake_schema.test", "comment", comment),
checkBool("snowflake_schema.test", "is_transient", false),
checkBool("snowflake_schema.test", "is_managed", false),
),
},
},
})
}

// TestAcc_Schema_TwoSchemasWithTheSameNameOnDifferentDatabases proves https://github.com/Snowflake-Labs/terraform-provider-snowflake/issues/2209 issue.
func TestAcc_Schema_TwoSchemasWithTheSameNameOnDifferentDatabases(t *testing.T) {
name := "test_schema"
newDatabaseName := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha))
newDatabaseName := "SELDQBXEKC"

resource.Test(t, resource.TestCase{
ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories,
Expand Down
5 changes: 5 additions & 0 deletions pkg/resources/testdata/TestAcc_Schema_Rename/test.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
resource "snowflake_schema" "test" {
name = var.name
database = var.database
comment = var.comment
}
11 changes: 11 additions & 0 deletions pkg/resources/testdata/TestAcc_Schema_Rename/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
variable "name" {
type = string
}

variable "database" {
type = string
}

variable "comment" {
type = string
}
8 changes: 4 additions & 4 deletions pkg/sdk/schemas.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,10 +389,10 @@ func (v *schemas) Show(ctx context.Context, opts *ShowSchemaOptions) ([]Schema,

func (v *schemas) ShowByID(ctx context.Context, id DatabaseObjectIdentifier) (*Schema, error) {
schemas, err := v.client.Schemas.Show(ctx, &ShowSchemaOptions{
//In: &SchemaIn{
// Database: Bool(true),
// Name: NewAccountObjectIdentifier(id.DatabaseName()),
//},
In: &SchemaIn{
Database: Bool(true),
Name: NewAccountObjectIdentifier(id.DatabaseName()),
},
Like: &Like{
Pattern: String(id.Name()),
},
Expand Down

0 comments on commit 9e0ac28

Please sign in to comment.