Skip to content

Commit

Permalink
provider/digitalocean: enhance user_data test
Browse files Browse the repository at this point in the history
Checks to ensure that the droplet is recreated. Commenting out
`ForceNew` on `user_data` fails the test now.

/cc @stack72
  • Loading branch information
phinze committed Nov 4, 2015
1 parent dbaa44a commit bf11be8
Showing 1 changed file with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func TestAccDigitalOceanDroplet_Update(t *testing.T) {
}

func TestAccDigitalOceanDroplet_UpdateUserData(t *testing.T) {
var droplet godo.Droplet
var afterCreate, afterUpdate godo.Droplet

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand All @@ -82,19 +82,21 @@ func TestAccDigitalOceanDroplet_UpdateUserData(t *testing.T) {
resource.TestStep{
Config: testAccCheckDigitalOceanDropletConfig_basic,
Check: resource.ComposeTestCheckFunc(
testAccCheckDigitalOceanDropletExists("digitalocean_droplet.foobar", &droplet),
testAccCheckDigitalOceanDropletAttributes(&droplet),
testAccCheckDigitalOceanDropletExists("digitalocean_droplet.foobar", &afterCreate),
testAccCheckDigitalOceanDropletAttributes(&afterCreate),
),
},

resource.TestStep{
Config: testAccCheckDigitalOceanDropletConfig_userdata_update,
Check: resource.ComposeTestCheckFunc(
testAccCheckDigitalOceanDropletExists("digitalocean_droplet.foobar", &droplet),
testAccCheckDigitalOceanDropletExists("digitalocean_droplet.foobar", &afterUpdate),
resource.TestCheckResourceAttr(
"digitalocean_droplet.foobar",
"user_data",
"foobar foobar"),
testAccCheckDigitalOceanDropletRecreated(
t, &afterCreate, &afterUpdate),
),
},
},
Expand Down Expand Up @@ -263,6 +265,16 @@ func testAccCheckDigitalOceanDropletExists(n string, droplet *godo.Droplet) reso
}
}

func testAccCheckDigitalOceanDropletRecreated(t *testing.T,
before, after *godo.Droplet) resource.TestCheckFunc {
return func(s *terraform.State) error {
if before.ID == after.ID {
t.Fatalf("Expected change of droplet IDs, but both were %v", before.ID)
}
return nil
}
}

// Not sure if this check should remain here as the underlaying
// function is changed and is tested indirectly by almost all
// other test already
Expand Down

1 comment on commit bf11be8

@stack72
Copy link
Contributor

@stack72 stack72 commented on bf11be8 Nov 4, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice @phinze - this makes a lot of sense now :)

Please sign in to comment.