From 64e400154c16e3afbb2cb4b34588234fe96a3767 Mon Sep 17 00:00:00 2001 From: Thomas Poindessous Date: Thu, 23 Mar 2017 12:05:14 +0100 Subject: [PATCH] Review by @paddyforan: better test possible network error --- resource_compute_snapshot_test.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/resource_compute_snapshot_test.go b/resource_compute_snapshot_test.go index 2460e845..cc74dc1f 100644 --- a/resource_compute_snapshot_test.go +++ b/resource_compute_snapshot_test.go @@ -8,6 +8,7 @@ import ( "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" "google.golang.org/api/compute/v1" + "google.golang.org/api/googleapi" ) func TestAccComputeSnapshot_basic(t *testing.T) { @@ -64,9 +65,15 @@ func testAccCheckComputeSnapshotDestroy(s *terraform.State) error { _, err := config.clientCompute.Snapshots.Get( config.Project, rs.Primary.ID).Do() - if err == nil { - return fmt.Errorf("Snapshot still exists") + if err != nil { + if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 { + return nil + } else if ok { + return fmt.Errorf("Error while requesting Google Cloud Plateform: http code error : %d, http message error: %s", gerr.Code, gerr.Message) + } + return fmt.Errorf("Error while requesting Google Cloud Plateform") } + return fmt.Errorf("Snapshot still exists") } return nil