From bf11be82c8ee131ddc5c001f3556817b99e7764f Mon Sep 17 00:00:00 2001 From: Paul Hinze Date: Wed, 4 Nov 2015 15:20:52 -0600 Subject: [PATCH] provider/digitalocean: enhance user_data test Checks to ensure that the droplet is recreated. Commenting out `ForceNew` on `user_data` fails the test now. /cc @stack72 --- .../resource_digitalocean_droplet_test.go | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/builtin/providers/digitalocean/resource_digitalocean_droplet_test.go b/builtin/providers/digitalocean/resource_digitalocean_droplet_test.go index 7f85034cb3d4..d3a37a82ca13 100644 --- a/builtin/providers/digitalocean/resource_digitalocean_droplet_test.go +++ b/builtin/providers/digitalocean/resource_digitalocean_droplet_test.go @@ -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) }, @@ -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), ), }, }, @@ -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