Skip to content

Commit ef80543

Browse files
Automated Tests for AlloyDB cluster (#7746) (#14353)
Signed-off-by: Modular Magician <[email protected]>
1 parent 9b76d75 commit ef80543

File tree

2 files changed

+160
-1
lines changed

2 files changed

+160
-1
lines changed

.changelog/7746.txt

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
```release-note:none
2+
Add Automated tests for AlloyDB cluster
3+
4+
```

google/resource_alloydb_cluster_test.go

+156-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ resource "google_alloydb_cluster" "default" {
5757
5858
lifecycle {
5959
prevent_destroy = true
60-
}
60+
}
6161
}
6262
6363
data "google_project" "project" {
@@ -305,3 +305,158 @@ resource "google_compute_network" "default" {
305305
}
306306
`, context)
307307
}
308+
309+
// The cluster creation should succeed with minimal number of arguments.
310+
func TestAccAlloydbCluster_mandatoryFields(t *testing.T) {
311+
t.Parallel()
312+
313+
context := map[string]interface{}{
314+
"random_suffix": RandString(t, 10),
315+
}
316+
317+
VcrTest(t, resource.TestCase{
318+
PreCheck: func() { AccTestPreCheck(t) },
319+
ProtoV5ProviderFactories: ProtoV5ProviderFactories(t),
320+
CheckDestroy: testAccCheckAlloydbClusterDestroyProducer(t),
321+
Steps: []resource.TestStep{
322+
{
323+
Config: testAccAlloydbCluster_alloydbClusterBasicExample(context),
324+
},
325+
},
326+
})
327+
}
328+
329+
// The cluster creation should succeed with maximal number of arguments.
330+
func TestAccAlloydbCluster_maximumFields(t *testing.T) {
331+
t.Parallel()
332+
333+
context := map[string]interface{}{
334+
"random_suffix": RandString(t, 10),
335+
}
336+
337+
VcrTest(t, resource.TestCase{
338+
PreCheck: func() { AccTestPreCheck(t) },
339+
ProtoV5ProviderFactories: ProtoV5ProviderFactories(t),
340+
CheckDestroy: testAccCheckAlloydbClusterDestroyProducer(t),
341+
Steps: []resource.TestStep{
342+
{
343+
Config: testAccAlloydbCluster_alloydbClusterFullExample(context),
344+
},
345+
},
346+
})
347+
}
348+
349+
// Deletion of time-based retention policy should be an in-place operation
350+
func TestAccAlloydbCluster_deleteTimeBasedRetentionPolicy(t *testing.T) {
351+
t.Parallel()
352+
353+
context := map[string]interface{}{
354+
"random_suffix": RandString(t, 10),
355+
}
356+
357+
VcrTest(t, resource.TestCase{
358+
PreCheck: func() { AccTestPreCheck(t) },
359+
ProtoV5ProviderFactories: ProtoV5ProviderFactories(t),
360+
CheckDestroy: testAccCheckAlloydbClusterDestroyProducer(t),
361+
Steps: []resource.TestStep{
362+
{
363+
Config: testAccAlloydbCluster_withTimeBasedRetentionPolicy(context),
364+
},
365+
{
366+
ResourceName: "google_alloydb_cluster.default",
367+
ImportState: true,
368+
ImportStateVerify: true,
369+
},
370+
{
371+
Config: testAccAlloydbCluster_withoutTimeBasedRetentionPolicy(context),
372+
},
373+
{
374+
ResourceName: "google_alloydb_cluster.default",
375+
ImportState: true,
376+
ImportStateVerify: true,
377+
},
378+
{
379+
Config: testAccAlloydbCluster_alloydbClusterBasicExample(context),
380+
},
381+
},
382+
})
383+
}
384+
385+
func testAccAlloydbCluster_withTimeBasedRetentionPolicy(context map[string]interface{}) string {
386+
return Nprintf(`
387+
resource "google_alloydb_cluster" "default" {
388+
cluster_id = "tf-test-alloydb-cluster%{random_suffix}"
389+
location = "us-central1"
390+
network = "projects/${data.google_project.project.number}/global/networks/${google_compute_network.default.name}"
391+
automated_backup_policy {
392+
location = "us-central1"
393+
backup_window = "1800s"
394+
enabled = true
395+
396+
weekly_schedule {
397+
days_of_week = ["MONDAY"]
398+
399+
start_times {
400+
hours = 23
401+
minutes = 0
402+
seconds = 0
403+
nanos = 0
404+
}
405+
}
406+
time_based_retention {
407+
retention_period = "4.5s"
408+
}
409+
}
410+
lifecycle {
411+
ignore_changes = [
412+
automated_backup_policy[0].time_based_retention
413+
]
414+
prevent_destroy = true
415+
}
416+
}
417+
418+
data "google_project" "project" { }
419+
420+
resource "google_compute_network" "default" {
421+
name = "tf-test-alloydb-cluster%{random_suffix}"
422+
}
423+
`, context)
424+
}
425+
426+
func testAccAlloydbCluster_withoutTimeBasedRetentionPolicy(context map[string]interface{}) string {
427+
return Nprintf(`
428+
resource "google_alloydb_cluster" "default" {
429+
cluster_id = "tf-test-alloydb-cluster%{random_suffix}"
430+
location = "us-central1"
431+
network = "projects/${data.google_project.project.number}/global/networks/${google_compute_network.default.name}"
432+
automated_backup_policy {
433+
location = "us-central1"
434+
backup_window = "1800s"
435+
enabled = true
436+
437+
weekly_schedule {
438+
days_of_week = ["MONDAY"]
439+
440+
start_times {
441+
hours = 23
442+
minutes = 0
443+
seconds = 0
444+
nanos = 0
445+
}
446+
}
447+
}
448+
lifecycle {
449+
ignore_changes = [
450+
automated_backup_policy[0].time_based_retention
451+
]
452+
prevent_destroy = true
453+
}
454+
}
455+
456+
data "google_project" "project" { }
457+
458+
resource "google_compute_network" "default" {
459+
name = "tf-test-alloydb-cluster%{random_suffix}"
460+
}
461+
`, context)
462+
}

0 commit comments

Comments
 (0)