@@ -2,9 +2,9 @@ package packet
22
33import (
44 "fmt"
5- "os"
65 "testing"
76
7+ "github.com/hashicorp/terraform/helper/acctest"
88 "github.com/hashicorp/terraform/helper/resource"
99 "github.com/hashicorp/terraform/terraform"
1010 "github.com/packethost/packngo"
@@ -13,20 +13,17 @@ import (
1313func TestAccPacketVolume_Basic (t * testing.T ) {
1414 var volume packngo.Volume
1515
16- project_id := os .Getenv ("PACKET_PROJECT_ID" )
17- facility := os .Getenv ("PACKET_FACILITY" )
16+ rs := acctest .RandString (10 )
1817
1918 resource .Test (t , resource.TestCase {
20- PreCheck : testAccPacketVolumePreCheck ( t ) ,
19+ PreCheck : func () { testAccPreCheck ( t ) } ,
2120 Providers : testAccProviders ,
2221 CheckDestroy : testAccCheckPacketVolumeDestroy ,
2322 Steps : []resource.TestStep {
2423 resource.TestStep {
25- Config : fmt .Sprintf (testAccCheckPacketVolumeConfig_basic , project_id , facility ),
24+ Config : fmt .Sprintf (testAccCheckPacketVolumeConfig_basic , rs ),
2625 Check : resource .ComposeTestCheckFunc (
2726 testAccCheckPacketVolumeExists ("packet_volume.foobar" , & volume ),
28- resource .TestCheckResourceAttr (
29- "packet_volume.foobar" , "project_id" , project_id ),
3027 resource .TestCheckResourceAttr (
3128 "packet_volume.foobar" , "plan" , "storage_1" ),
3229 resource .TestCheckResourceAttr (
@@ -80,24 +77,16 @@ func testAccCheckPacketVolumeExists(n string, volume *packngo.Volume) resource.T
8077 }
8178}
8279
83- func testAccPacketVolumePreCheck (t * testing.T ) func () {
84- return func () {
85- testAccPreCheck (t )
86- if os .Getenv ("PACKET_PROJECT_ID" ) == "" {
87- t .Fatal ("PACKET_PROJECT_ID must be set" )
88- }
89- if os .Getenv ("PACKET_FACILITY" ) == "" {
90- t .Fatal ("PACKET_FACILITY must be set" )
91- }
92- }
80+ const testAccCheckPacketVolumeConfig_basic = `
81+ resource "packet_project" "foobar" {
82+ name = "%s"
9383}
9484
95- const testAccCheckPacketVolumeConfig_basic = `
9685resource "packet_volume" "foobar" {
9786 plan = "storage_1"
9887 billing_cycle = "hourly"
9988 size = 100
100- project_id = "%s "
101- facility = "%s "
89+ project_id = "${packet_project.foobar.id} "
90+ facility = "ewr1 "
10291 snapshot_policies = { snapshot_frequency = "1day", snapshot_count = 7 }
10392}`
0 commit comments