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

add tests #7357

Merged
merged 1 commit into from
Mar 8, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ func TestAccSpannerDatabase_basic(t *testing.T) {
Providers: testAccProviders,
CheckDestroy: testAccCheckSpannerDatabaseDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccSpannerDatabase_virtualUpdate(instanceName, databaseName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("google_spanner_database.basic", "state"),
resource.TestCheckResourceAttr("google_spanner_database.basic", "version_retention_period", "1h"), // default set by API
),
},
{
Config: testAccSpannerDatabase_basic(instanceName, databaseName),
Check: resource.ComposeTestCheckFunc(
Expand Down Expand Up @@ -120,6 +127,27 @@ resource "google_spanner_database" "basic" {
`, instanceName, instanceName, databaseName)
}

func testAccSpannerDatabase_virtualUpdate(instanceName, databaseName string) string {
return fmt.Sprintf(`
resource "google_spanner_instance" "basic" {
name = "%s"
config = "regional-us-central1"
display_name = "%s-display"
num_nodes = 1
}

resource "google_spanner_database" "basic" {
instance = google_spanner_instance.basic.name
name = "%s"
ddl = [
"CREATE TABLE t1 (t1 INT64 NOT NULL,) PRIMARY KEY(t1)",
"CREATE TABLE t2 (t2 INT64 NOT NULL,) PRIMARY KEY(t2)",
]
deletion_protection = true
}
`, instanceName, instanceName, databaseName)
}

func TestAccSpannerDatabase_postgres(t *testing.T) {
t.Parallel()

Expand Down
41 changes: 41 additions & 0 deletions mmv1/third_party/terraform/tests/resource_spanner_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,35 @@ func TestAccSpannerInstance_update(t *testing.T) {
})
}

func TestAccSpannerInstance_virtualUpdate(t *testing.T) {
// Randomness
skipIfVcr(t)
t.Parallel()

dName := fmt.Sprintf("spanner-dname1-%s", randString(t, 10))
vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckSpannerInstanceDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccSpannerInstance_virtualUpdate(dName, "true"),
},
{
ResourceName: "google_spanner_instance.basic",
ImportState: true,
},
{
Config: testAccSpannerInstance_virtualUpdate(dName, "false"),
},
{
ResourceName: "google_spanner_instance.basic",
ImportState: true,
},
},
})
}

func testAccSpannerInstance_basic(name string) string {
return fmt.Sprintf(`
resource "google_spanner_instance" "basic" {
Expand Down Expand Up @@ -196,3 +225,15 @@ resource "google_spanner_instance" "updater" {
}
`, name, nodes, extraLabel)
}

func testAccSpannerInstance_virtualUpdate(name, virtual string) string {
return fmt.Sprintf(`
resource "google_spanner_instance" "basic" {
name = "%s"
config = "regional-us-central1"
display_name = "%s"
processing_units = 100
force_destroy = "%s"
}
`, name, name, virtual)
}