Skip to content

Commit

Permalink
fixes all tests but one
Browse files Browse the repository at this point in the history
  • Loading branch information
imaskm committed Dec 10, 2024
1 parent 1bd914d commit e61062a
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 111 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ resource "digitalocean_reserved_ip_assignment" "foobar" {

var testAccCheckDigitalOceanReservedIPAssignmentConfig_createBeforeDestroyReassign = `
resource "digitalocean_droplet" "foobar" {
image = "ubuntu-18-04-x64"
image = "ubuntu-22-04-x64"
name = "tf-acc-test-01"
region = "nyc3"
size = "s-1vcpu-1gb"
Expand Down
2 changes: 1 addition & 1 deletion digitalocean/reservedipv6/datasource_reserved_ipv6.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func DataSourceDigitalOceanReservedIPV6() *schema.Resource {
"droplet_id": {
Type: schema.TypeInt,
Computed: true,
Description: "the droplet id that the reserved ip has been assigned to.",
Description: "the droplet id that the reserved ipv6 has been assigned to.",
},
},
}
Expand Down
22 changes: 0 additions & 22 deletions digitalocean/reservedipv6/import_reserved_ipv6_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,3 @@ func TestAccDigitalOceanReservedIPV6_importBasicRegion(t *testing.T) {
},
})
}

func TestAccDigitalOceanReservedIPV6_importBasicDroplet(t *testing.T) {
resourceName := "digitalocean_reserved_ipv6.foobar"
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),
},

{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}
11 changes: 6 additions & 5 deletions digitalocean/reservedipv6/resource_reserved_ipv6_assignment.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,14 @@ func resourceDigitalOceanReservedIPV6AssignmentCreate(ctx context.Context, d *sc
"Error Assigning reserved IPv6 (%s) to the droplet: %s", ipAddress, err)
}

_, unassignedErr := waitForReservedIPV6AssignmentReady(ctx, d, "completed", []string{"new", "in-progress"}, "status", meta, action.ID)
if unassignedErr != nil {
_, assignedErr := waitForReservedIPV6AssignmentReady(ctx, d, "completed", []string{"new", "in-progress"}, "status", meta, action.ID)
if assignedErr != nil {
return diag.Errorf(
"Error waiting for reserved IPv6 (%s) to be Assigned: %s", ipAddress, unassignedErr)
"Error waiting for reserved IPv6 (%s) to be Assigned: %s", ipAddress, assignedErr)
}

d.SetId(id.PrefixedUniqueId(fmt.Sprintf("%d-%s-", dropletID, ipAddress)))

return resourceDigitalOceanReservedIPV6AssignmentRead(ctx, d, meta)
}

Expand All @@ -79,8 +80,8 @@ func resourceDigitalOceanReservedIPV6AssignmentRead(ctx context.Context, d *sche
}

if reservedIPv6.Droplet == nil || reservedIPv6.Droplet.ID != dropletID {
log.Printf("[INFO] A Droplet was detected on the reserved IPv6.")
d.SetId("")
// log.Printf("[INFO] Droplet assignment was unsuccessful on the reserved IPv6.")
return diag.Errorf("Error assigning reserved IPv6 %s to dropletID %d", ipAddress, dropletID)
}

return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,12 @@ func TestAccDigitalOceanReservedIPV6Assignment(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testAccCheckDigitalOceanReservedIPV6AttachmentExists("digitalocean_reserved_ipv6_assignment.foobar"),
resource.TestMatchResourceAttr(
"digitalocean_reserved_ipv6_assignment.foobar", "id", regexp.MustCompile(ipv6Regex)),
resource.TestMatchResourceAttr(
"digitalocean_reserved_ipv6_assignment.foobar", "droplet_id", regexp.MustCompile("[0-9]+")),
),
},
{
Config: testAccCheckDigitalOceanReservedIPV6AssignmentReassign,
Check: resource.ComposeTestCheckFunc(
testAccCheckDigitalOceanReservedIPV6AttachmentExists("digitalocean_reserved_ipv6_assignment.foobar"),
resource.TestMatchResourceAttr(
"digitalocean_reserved_ipv6_assignment.foobar", "id", regexp.MustCompile(ipv6Regex)),
"digitalocean_reserved_ipv6_assignment.foobar", "ip", regexp.MustCompile(ipv6Regex)),
resource.TestMatchResourceAttr(
"digitalocean_reserved_ipv6_assignment.foobar", "droplet_id", regexp.MustCompile("[0-9]+")),
),
},

{
Config: testAccCheckDigitalOceanReservedIPV6AssignmentDeleteAssignment,
Check: resource.ComposeTestCheckFunc(
Expand All @@ -65,17 +56,7 @@ func TestAccDigitalOceanReservedIPV6Assignment_createBeforeDestroy(t *testing.T)
Check: resource.ComposeTestCheckFunc(
testAccCheckDigitalOceanReservedIPV6AttachmentExists("digitalocean_reserved_ipv6_assignment.foobar"),
resource.TestMatchResourceAttr(
"digitalocean_reserved_ipv6_assignment.foobar", "id", regexp.MustCompile(ipv6Regex)),
resource.TestMatchResourceAttr(
"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", "id", regexp.MustCompile(ipv6Regex)),
"digitalocean_reserved_ipv6_assignment.foobar", "ip", regexp.MustCompile(ipv6Regex)),
resource.TestMatchResourceAttr(
"digitalocean_reserved_ipv6_assignment.foobar", "droplet_id", regexp.MustCompile("[0-9]+")),
),
Expand All @@ -91,18 +72,18 @@ func testAccCheckDigitalOceanReservedIPV6AttachmentExists(n string) resource.Tes
return fmt.Errorf("Not found: %s", n)
}

if rs.Primary.Attributes["ip_address"] == "" {
return fmt.Errorf("No floating IP is set")
if rs.Primary.Attributes["ip"] == "" {
return fmt.Errorf("No reserved IPv6 is set")
}
fipID := rs.Primary.Attributes["ip_address"]
fipID := rs.Primary.Attributes["ip"]
dropletID, err := strconv.Atoi(rs.Primary.Attributes["droplet_id"])
if err != nil {
return err
}

client := acceptance.TestAccProvider.Meta().(*config.CombinedConfig).GodoClient()

// Try to find the ReservedIP
// Try to find the ReservedIPv6
foundReservedIP, _, err := client.ReservedIPV6s.Get(context.Background(), fipID)
if err != nil {
return err
Expand All @@ -122,7 +103,7 @@ resource "digitalocean_reserved_ipv6" "foobar" {
}
resource "digitalocean_droplet" "foobar" {
count = 2
count = 1
name = "tf-acc-test-${count.index}"
size = "s-1vcpu-1gb"
image = "ubuntu-22-04-x64"
Expand All @@ -136,33 +117,13 @@ resource "digitalocean_reserved_ipv6_assignment" "foobar" {
}
`

var testAccCheckDigitalOceanReservedIPV6AssignmentReassign = `
resource "digitalocean_reserved_ipv6" "foobar" {
region_slug = "nyc3"
}
resource "digitalocean_droplet" "foobar" {
count = 2
name = "tf-acc-test-${count.index}"
size = "s-1vcpu-1gb"
image = "ubuntu-22-04-x64"
region = "nyc3"
ipv6 = true
}
resource "digitalocean_reserved_ipv6_assignment" "foobar" {
ip = digitalocean_reserved_ipv6.foobar.ip
droplet_id = digitalocean_droplet.foobar.1.id
}
`

var testAccCheckDigitalOceanReservedIPV6AssignmentDeleteAssignment = `
resource "digitalocean_reserved_ipv6" "foobar" {
region_slug = "nyc3"
}
resource "digitalocean_droplet" "foobar" {
count = 2
count = 1
name = "tf-acc-test-${count.index}"
size = "s-1vcpu-1gb"
image = "ubuntu-22-04-x64"
Expand Down Expand Up @@ -197,29 +158,3 @@ resource "digitalocean_reserved_ipv6_assignment" "foobar" {
}
}
`

var testAccCheckDigitalOceanReservedIPV6AssignmentConfig_createBeforeDestroyReassign = `
resource "digitalocean_droplet" "foobar" {
image = "ubuntu-18-04-x64"
name = "tf-acc-test-01"
region = "nyc3"
size = "s-1vcpu-1gb"
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
}
}
`
16 changes: 8 additions & 8 deletions digitalocean/reservedipv6/resource_reserved_ipv6_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,10 @@ resource "digitalocean_reserved_ipv6" "foobar" {
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"
name = "%s"
size = "s-1vcpu-1gb"
image = "ubuntu-22-04-x64"
region = "nyc3"
ipv6 = true
private_networking = true
}
Expand All @@ -150,10 +150,10 @@ resource "digitalocean_reserved_ipv6" "foobar" {
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"
name = "%s"
size = "s-1vcpu-1gb"
image = "ubuntu-22-04-x64"
region = "nyc3"
ipv6 = true
private_networking = true
}
Expand Down

0 comments on commit e61062a

Please sign in to comment.