-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed error in volume attachment cmd Added the test for volume attachment Signed-off-by: Alejandro JNM <alejandrojnm@gmail.com>
- Loading branch information
1 parent
b73725b
commit 0c87d35
Showing
2 changed files
with
72 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package civo | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/civo/civogo" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-sdk/terraform" | ||
) | ||
|
||
// example.Widget represents a concrete Go type that represents an API resource | ||
func TestAccCivoVolumeAttachment_basic(t *testing.T) { | ||
var volume civogo.Volume | ||
|
||
// generate a random name for each test run | ||
resName := "civo_volume_attachment.foobar" | ||
var VolumeAttachmentName = acctest.RandomWithPrefix("tf-test") | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckCivoVolumeAttachmentDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
// use a dynamic configuration with the random name from above | ||
Config: testAccCheckCivoVolumeAttachmentConfigBasic(VolumeAttachmentName), | ||
// compose a basic test, checking both remote and local values | ||
Check: resource.ComposeTestCheckFunc( | ||
// query the API to retrieve the widget object | ||
testAccCheckCivoVolumeResourceExists("civo_volume.foo", &volume), | ||
// verify local values | ||
resource.TestCheckResourceAttrSet(resName, "id"), | ||
resource.TestCheckResourceAttrSet(resName, "instance_id"), | ||
resource.TestCheckResourceAttrSet(resName, "volume_id"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccCheckCivoVolumeAttachmentDestroy(s *terraform.State) error { | ||
for _, rs := range s.RootModule().Resources { | ||
if rs.Type != "civo_volume_attachment" { | ||
continue | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func testAccCheckCivoVolumeAttachmentConfigBasic(name string) string { | ||
return fmt.Sprintf(` | ||
resource "civo_instance" "vm" { | ||
hostname = "instance-%s" | ||
} | ||
resource "civo_volume" "foo" { | ||
name = "%s" | ||
size_gb = 60 | ||
bootable = false | ||
} | ||
resource "civo_volume_attachment" "foobar" { | ||
instance_id = civo_instance.vm.id | ||
volume_id = civo_volume.foo.id | ||
} | ||
`, name, name) | ||
} |