provider/packet: Restructure the Packet Volume test to no longer rely on environment variables
This commit is contained in:
parent
fdb168e433
commit
ffd04882e7
|
@ -2,9 +2,9 @@ package packet
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/hashicorp/terraform/helper/acctest"
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
"github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
"github.com/packethost/packngo"
|
"github.com/packethost/packngo"
|
||||||
|
@ -13,20 +13,17 @@ import (
|
||||||
func TestAccPacketVolume_Basic(t *testing.T) {
|
func TestAccPacketVolume_Basic(t *testing.T) {
|
||||||
var volume packngo.Volume
|
var volume packngo.Volume
|
||||||
|
|
||||||
project_id := os.Getenv("PACKET_PROJECT_ID")
|
rs := acctest.RandString(10)
|
||||||
facility := os.Getenv("PACKET_FACILITY")
|
|
||||||
|
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: testAccPacketVolumePreCheck(t),
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
CheckDestroy: testAccCheckPacketVolumeDestroy,
|
CheckDestroy: testAccCheckPacketVolumeDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: fmt.Sprintf(testAccCheckPacketVolumeConfig_basic, project_id, facility),
|
Config: fmt.Sprintf(testAccCheckPacketVolumeConfig_basic, rs),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckPacketVolumeExists("packet_volume.foobar", &volume),
|
testAccCheckPacketVolumeExists("packet_volume.foobar", &volume),
|
||||||
resource.TestCheckResourceAttr(
|
|
||||||
"packet_volume.foobar", "project_id", project_id),
|
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
"packet_volume.foobar", "plan", "storage_1"),
|
"packet_volume.foobar", "plan", "storage_1"),
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
|
@ -80,24 +77,16 @@ func testAccCheckPacketVolumeExists(n string, volume *packngo.Volume) resource.T
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAccPacketVolumePreCheck(t *testing.T) func() {
|
const testAccCheckPacketVolumeConfig_basic = `
|
||||||
return func() {
|
resource "packet_project" "foobar" {
|
||||||
testAccPreCheck(t)
|
name = "%s"
|
||||||
if os.Getenv("PACKET_PROJECT_ID") == "" {
|
|
||||||
t.Fatal("PACKET_PROJECT_ID must be set")
|
|
||||||
}
|
|
||||||
if os.Getenv("PACKET_FACILITY") == "" {
|
|
||||||
t.Fatal("PACKET_FACILITY must be set")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const testAccCheckPacketVolumeConfig_basic = `
|
|
||||||
resource "packet_volume" "foobar" {
|
resource "packet_volume" "foobar" {
|
||||||
plan = "storage_1"
|
plan = "storage_1"
|
||||||
billing_cycle = "hourly"
|
billing_cycle = "hourly"
|
||||||
size = 100
|
size = 100
|
||||||
project_id = "%s"
|
project_id = "${packet_project.foobar.id}"
|
||||||
facility = "%s"
|
facility = "ewr1"
|
||||||
snapshot_policies = { snapshot_frequency = "1day", snapshot_count = 7 }
|
snapshot_policies = { snapshot_frequency = "1day", snapshot_count = 7 }
|
||||||
}`
|
}`
|
||||||
|
|
Loading…
Reference in New Issue