Skip to content

Commit

Permalink
fixed test failures
Browse files Browse the repository at this point in the history
  • Loading branch information
imaskm committed Dec 10, 2024
1 parent e61062a commit 646e5e8
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 87 deletions.
2 changes: 1 addition & 1 deletion digitalocean/reservedipv6/resource_reserved_ipv6.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func resourceDigitalOceanReservedIPV6Create(ctx context.Context, d *schema.Resou
log.Printf("[DEBUG] Reserved IPv6 create: %#v", regionOpts)
reservedIP, _, err := client.ReservedIPV6s.Create(context.Background(), regionOpts)
if err != nil {
return diag.Errorf("Error creating reserved IP: %s", err)
return diag.Errorf("Error creating reserved IPv6: %s", err)
}

d.SetId(reservedIP.IP)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@ func TestAccDigitalOceanReservedIPV6Assignment_createBeforeDestroy(t *testing.T)
"digitalocean_reserved_ipv6_assignment.foobar", "droplet_id", regexp.MustCompile("[0-9]+")),
),
},
{
Config: testAccCheckDigitalOceanReservedIPV6AssignmentConfig_createBeforeDestroyReassign,
Check: resource.ComposeTestCheckFunc(
testAccCheckDigitalOceanReservedIPV6AttachmentExists("digitalocean_reserved_ipv6_assignment.foobar"),
resource.TestMatchResourceAttr(
"digitalocean_reserved_ipv6_assignment.foobar", "ip", regexp.MustCompile(ipv6Regex)),
resource.TestMatchResourceAttr(
"digitalocean_reserved_ipv6_assignment.foobar", "droplet_id", regexp.MustCompile("[0-9]+")),
),
},
},
})
}
Expand Down Expand Up @@ -139,6 +149,33 @@ resource "digitalocean_droplet" "foobar" {
name = "tf-acc-test"
region = "nyc3"
size = "s-1vcpu-1gb"
ipv6 = true
lifecycle {
create_before_destroy = true
}
}
resource "digitalocean_reserved_ipv6" "foobar" {
region_slug = "nyc3"
}
resource "digitalocean_reserved_ipv6_assignment" "foobar" {
ip = digitalocean_reserved_ipv6.foobar.ip
droplet_id = digitalocean_droplet.foobar.id
lifecycle {
create_before_destroy = true
}
}
`
var testAccCheckDigitalOceanReservedIPV6AssignmentConfig_createBeforeDestroyReassign = `
resource "digitalocean_droplet" "foobar" {
image = "ubuntu-22-04-x64"
name = "tf-acc-test-01"
region = "nyc3"
size = "s-1vcpu-1gb"
ipv6 = true
lifecycle {
create_before_destroy = true
Expand Down
86 changes: 0 additions & 86 deletions digitalocean/reservedipv6/resource_reserved_ipv6_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,43 +38,6 @@ func TestAccDigitalOceanReservedIPV6_RegionSlug(t *testing.T) {
})
}

func TestAccDigitalOceanReservedIPV6_Droplet(t *testing.T) {
var reservedIPv6 godo.ReservedIPV6
name := acceptance.RandomTestName()

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.TestAccPreCheck(t) },
ProviderFactories: acceptance.TestAccProviderFactories,
CheckDestroy: testAccCheckDigitalOceanReservedIPV6Destroy,
Steps: []resource.TestStep{
{
Config: testAccCheckDigitalOceanReservedIPV6Config_droplet(name),
Check: resource.ComposeTestCheckFunc(
testAccCheckDigitalOceanReservedIPV6Exists("digitalocean_reserved_ipv6.foobar", &reservedIPv6),
resource.TestCheckResourceAttr(
"digitalocean_reserved_ipv6.foobar", "region_slug", "nyc3"),
),
},
{
Config: testAccCheckDigitalOceanReservedIPv6Config_Reassign(name),
Check: resource.ComposeTestCheckFunc(
testAccCheckDigitalOceanReservedIPV6Exists("digitalocean_reserved_ipv6.foobar", &reservedIPv6),
resource.TestCheckResourceAttr(
"digitalocean_reserved_ipv6.foobar", "region_slug", "nyc3"),
),
},
{
Config: testAccCheckDigitalOceanReservedIPV6Config_Unassign(name),
Check: resource.ComposeTestCheckFunc(
testAccCheckDigitalOceanReservedIPV6Exists("digitalocean_reserved_ipv6.foobar", &reservedIPv6),
resource.TestCheckResourceAttr(
"digitalocean_reserved_ipv6.foobar", "region_slug", "nyc3"),
),
},
},
})
}

func testAccCheckDigitalOceanReservedIPV6Destroy(s *terraform.State) error {
client := acceptance.TestAccProvider.Meta().(*config.CombinedConfig).GodoClient()

Expand Down Expand Up @@ -129,52 +92,3 @@ var testAccCheckDigitalOceanReservedIPV6Config_regionSlug = `
resource "digitalocean_reserved_ipv6" "foobar" {
region_slug = "nyc3"
}`

func testAccCheckDigitalOceanReservedIPV6Config_droplet(name string) string {
return fmt.Sprintf(`
resource "digitalocean_droplet" "foobar" {
name = "%s"
size = "s-1vcpu-1gb"
image = "ubuntu-22-04-x64"
region = "nyc3"
ipv6 = true
private_networking = true
}
resource "digitalocean_reserved_ipv6" "foobar" {
droplet_id = digitalocean_droplet.foobar.id
region_slug = digitalocean_droplet.foobar.region
}`, name)
}

func testAccCheckDigitalOceanReservedIPv6Config_Reassign(name string) string {
return fmt.Sprintf(`
resource "digitalocean_droplet" "baz" {
name = "%s"
size = "s-1vcpu-1gb"
image = "ubuntu-22-04-x64"
region = "nyc3"
ipv6 = true
private_networking = true
}
resource "digitalocean_reserved_ipv6" "foobar" {
droplet_id = digitalocean_droplet.baz.id
region_slug = digitalocean_droplet.baz.region
}`, name)
}

func testAccCheckDigitalOceanReservedIPV6Config_Unassign(name string) string {
return fmt.Sprintf(`
resource "digitalocean_droplet" "baz" {
name = "%s"
size = "s-1vcpu-1gb"
image = "ubuntu-22-04-x64"
region = "nyc3"
ipv6 = true
}
resource "digitalocean_reserved_ipv6" "foobar" {
region_slug = "nyc3"
}`, name)
}

0 comments on commit 646e5e8

Please sign in to comment.