Skip to content

Commit

Permalink
Add test case for wait_for_available linode_rdns
Browse files Browse the repository at this point in the history
  • Loading branch information
LBGarber committed Jan 4, 2022
1 parent 03abf4f commit 05f0cb0
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 9 deletions.
46 changes: 43 additions & 3 deletions linode/rdns/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func TestAccResourceRDNS_basic(t *testing.T) {
CheckDestroy: checkRDNSDestroy,
Steps: []resource.TestStep{
{
Config: tmpl.Basic(t, linodeLabel),
Config: tmpl.Basic(t, linodeLabel, false),
Check: resource.ComposeTestCheckFunc(
checkRDNSExists,
resource.TestMatchResourceAttr(resName, "rdns", regexp.MustCompile(`.nip.io$`)),
Expand Down Expand Up @@ -87,15 +87,55 @@ func TestAccResourceRDNS_update(t *testing.T) {
CheckDestroy: checkRDNSDestroy,
Steps: []resource.TestStep{
{
Config: tmpl.Basic(t, label),
Config: tmpl.Basic(t, label, false),
Check: resource.ComposeTestCheckFunc(
checkRDNSExists,
resource.TestCheckResourceAttrPair(resName, "address", "linode_instance.foobar", "ip_address"),
resource.TestMatchResourceAttr(resName, "rdns", regexp.MustCompile(`([0-9]{1,3}\.){4}nip.io$`)),
),
},
{
Config: tmpl.Changed(t, label),
Config: tmpl.Changed(t, label, false),
Check: resource.ComposeTestCheckFunc(
checkRDNSExists,
resource.TestMatchResourceAttr(resName, "rdns", regexp.MustCompile(`([0-9]{1,3}\-){3}[0-9]{1,3}.nip.io$`)),
),
},
{
Config: tmpl.Deleted(t, label),
},
{
Config: tmpl.Deleted(t, label),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestMatchResourceAttr("data.linode_networking_ip.foobar", "rdns", regexp.MustCompile(`.ip.linodeusercontent.com$`)),
),
},
},
})
}

// This test case simply ensures a
func TestAccResourceRDNS_waitForAvailable(t *testing.T) {
t.Parallel()

var label = acctest.RandomWithPrefix("tf_test")
resName := "linode_rdns.foobar"

resource.Test(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.TestAccProviders,
CheckDestroy: checkRDNSDestroy,
Steps: []resource.TestStep{
{
Config: tmpl.Basic(t, label, true),
Check: resource.ComposeTestCheckFunc(
checkRDNSExists,
resource.TestCheckResourceAttrPair(resName, "address", "linode_instance.foobar", "ip_address"),
resource.TestMatchResourceAttr(resName, "rdns", regexp.MustCompile(`([0-9]{1,3}\.){4}nip.io$`)),
),
},
{
Config: tmpl.Changed(t, label, true),
Check: resource.ComposeTestCheckFunc(
checkRDNSExists,
resource.TestMatchResourceAttr(resName, "rdns", regexp.MustCompile(`([0-9]{1,3}\-){3}[0-9]{1,3}.nip.io$`)),
Expand Down
1 change: 1 addition & 0 deletions linode/rdns/tmpl/basic.gotf
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ resource "linode_instance" "foobar" {
resource "linode_rdns" "foobar" {
address = "${linode_instance.foobar.ip_address}"
rdns = "${linode_instance.foobar.ip_address}.nip.io"
wait_for_available = {{.WaitForAvailable}}
}

{{ end }}
1 change: 1 addition & 0 deletions linode/rdns/tmpl/changed.gotf
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ resource "linode_instance" "foobar" {
resource "linode_rdns" "foobar" {
rdns = "${replace(linode_instance.foobar.ip_address, ".", "-")}.nip.io"
address = "${linode_instance.foobar.ip_address}"
wait_for_available = {{.WaitForAvailable}}
}

{{ end }}
Expand Down
21 changes: 15 additions & 6 deletions linode/rdns/tmpl/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,29 @@ import (
)

type TemplateData struct {
Label string
Label string
WaitForAvailable bool
}

func Basic(t *testing.T, label string) string {
func Basic(t *testing.T, label string, waitForAvailable bool) string {
return acceptance.ExecuteTemplate(t,
"rdns_basic", TemplateData{Label: label})
"rdns_basic", TemplateData{
Label: label,
WaitForAvailable: waitForAvailable,
})
}

func Changed(t *testing.T, label string) string {
func Changed(t *testing.T, label string, waitForAvailable bool) string {
return acceptance.ExecuteTemplate(t,
"rdns_changed", TemplateData{Label: label})
"rdns_changed", TemplateData{
Label: label,
WaitForAvailable: waitForAvailable,
})
}

func Deleted(t *testing.T, label string) string {
return acceptance.ExecuteTemplate(t,
"rdns_deleted", TemplateData{Label: label})
"rdns_deleted", TemplateData{
Label: label,
})
}

0 comments on commit 05f0cb0

Please sign in to comment.