diff options
author | Duncan Mac-Vicar P <dmacvicar@suse.de> | 2016-03-12 23:59:54 +0100 |
---|---|---|
committer | Duncan Mac-Vicar P <dmacvicar@suse.de> | 2016-03-12 23:59:54 +0100 |
commit | 5a06a609c6c391b8a88278061e59b75eb3af5b89 (patch) | |
tree | fb6e80d0ded2438376b78b0abc6cc887126a062b | |
parent | 30d71a83fdc734a41006409420ae6343f463567e (diff) | |
download | terraform-provider-libvirt-5a06a609c6c391b8a88278061e59b75eb3af5b89.tar terraform-provider-libvirt-5a06a609c6c391b8a88278061e59b75eb3af5b89.tar.gz |
volume removal test
-rw-r--r-- | libvirt/resource_libvirt_domain_test.go | 12 | ||||
-rw-r--r-- | libvirt/resource_libvirt_volume_test.go | 15 |
2 files changed, 18 insertions, 9 deletions
diff --git a/libvirt/resource_libvirt_domain_test.go b/libvirt/resource_libvirt_domain_test.go index 28f2467a..dc807448 100644 --- a/libvirt/resource_libvirt_domain_test.go +++ b/libvirt/resource_libvirt_domain_test.go @@ -85,6 +85,11 @@ func TestAccLibvirtDomain_Volume(t *testing.T) { } }`) + var configVolDettached = fmt.Sprintf(` + resource "libvirt_domain" "acceptance-test-domain" { + name = "terraform-test" + }`) + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, @@ -97,6 +102,13 @@ func TestAccLibvirtDomain_Volume(t *testing.T) { testAccCheckLibvirtVolumeExists("libvirt_volume.acceptance-test-volume", &volume), ), }, + resource.TestStep{ + Config: configVolDettached, + Check: resource.ComposeTestCheckFunc( + testAccCheckLibvirtDomainExists("libvirt_domain.acceptance-test-domain", &domain), + testAccCheckLibvirtVolumeDoesNotExists("libvirt_volume.acceptance-test-volume", &volume), + ), + }, }, }) } diff --git a/libvirt/resource_libvirt_volume_test.go b/libvirt/resource_libvirt_volume_test.go index b82e42c5..a039fa61 100644 --- a/libvirt/resource_libvirt_volume_test.go +++ b/libvirt/resource_libvirt_volume_test.go @@ -88,18 +88,15 @@ func testAccCheckLibvirtVolumeDoesNotExists(n string, volume *libvirt.VirStorage return func(s *terraform.State) error { virConn := testAccProvider.Meta().(*Client).libvirt - rs, ok := s.RootModule().Resources[n] - if !ok { - return fmt.Errorf("Not found: %s", n) - } - - if rs.Primary.ID == "" { - return fmt.Errorf("No libvirt volume key ID is set") + key, err := volume.GetKey() + if err != nil { + return fmt.Errorf("Can't retrieve volume key: %s", err) } - _, err := virConn.LookupStorageVolByKey(rs.Primary.ID) + vol, err := virConn.LookupStorageVolByKey(key) + defer vol.Free() if err == nil { - return fmt.Errorf("Volume still exists") + return fmt.Errorf("Volume '%s' still exists", key) } |