update acceptance tests for packet volume, update packngo api client
This commit is contained in:
parent
18814655f8
commit
d60cf4d777
|
@ -38,7 +38,7 @@ func testAccCheckPacketProjectDestroy(s *terraform.State) error {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if _, _, err := client.Projects.Get(rs.Primary.ID); err == nil {
|
if _, _, err := client.Projects.Get(rs.Primary.ID); err == nil {
|
||||||
return fmt.Errorf("Project cstill exists")
|
return fmt.Errorf("Project still exists")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ package packet
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
|
@ -12,24 +13,26 @@ 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")
|
||||||
|
facility := os.Getenv("PACKET_FACILITY")
|
||||||
|
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: testAccPacketVolumePreCheck(t),
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
CheckDestroy: testAccCheckPacketVolumeDestroy,
|
CheckDestroy: testAccCheckPacketVolumeDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: testAccCheckPacketVolumeConfig_basic,
|
Config: fmt.Sprintf(testAccCheckPacketVolumeConfig_basic, project_id, facility),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckPacketVolumeExists("packet_volume.foobar", &volume),
|
testAccCheckPacketVolumeExists("packet_volume.foobar", &volume),
|
||||||
testAccCheckPacketVolumeAttributes(&volume),
|
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
"packet_volume.foobar", "project_id", "foobar"),
|
"packet_volume.foobar", "project_id", project_id),
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
"packet_volume.foobar", "plan", "foobar"),
|
"packet_volume.foobar", "plan", "storage_1"),
|
||||||
resource.TestCheckResourceAttr(
|
|
||||||
"packet_volume.foobar", "facility", "foobar"),
|
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
"packet_volume.foobar", "billing_cycle", "hourly"),
|
"packet_volume.foobar", "billing_cycle", "hourly"),
|
||||||
|
resource.TestCheckResourceAttr(
|
||||||
|
"packet_volume.foobar", "size", "100"),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -44,22 +47,13 @@ func testAccCheckPacketVolumeDestroy(s *terraform.State) error {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if _, _, err := client.Volumes.Get(rs.Primary.ID); err == nil {
|
if _, _, err := client.Volumes.Get(rs.Primary.ID); err == nil {
|
||||||
return fmt.Errorf("Volume cstill exists")
|
return fmt.Errorf("Volume still exists")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAccCheckPacketVolumeAttributes(volume *packngo.Volume) resource.TestCheckFunc {
|
|
||||||
return func(s *terraform.State) error {
|
|
||||||
if volume.Name != "foobar" {
|
|
||||||
return fmt.Errorf("Bad name: %s", volume.Name)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func testAccCheckPacketVolumeExists(n string, volume *packngo.Volume) resource.TestCheckFunc {
|
func testAccCheckPacketVolumeExists(n string, volume *packngo.Volume) resource.TestCheckFunc {
|
||||||
return func(s *terraform.State) error {
|
return func(s *terraform.State) error {
|
||||||
rs, ok := s.RootModule().Resources[n]
|
rs, ok := s.RootModule().Resources[n]
|
||||||
|
@ -86,10 +80,23 @@ func testAccCheckPacketVolumeExists(n string, volume *packngo.Volume) resource.T
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var testAccCheckPacketVolumeConfig_basic = fmt.Sprintf(`
|
func testAccPacketVolumePreCheck(t *testing.T) func() {
|
||||||
|
return func() {
|
||||||
|
testAccPreCheck(t)
|
||||||
|
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" {
|
||||||
project_id = "foobar"
|
plan = "storage_1"
|
||||||
plan = "foobar"
|
|
||||||
facility = "foobar"
|
|
||||||
billing_cycle = "hourly"
|
billing_cycle = "hourly"
|
||||||
}`)
|
size = 100
|
||||||
|
project_id = "%s"
|
||||||
|
facility = "%s"
|
||||||
|
}`
|
||||||
|
|
|
@ -82,7 +82,7 @@ type VolumeServiceOp struct {
|
||||||
|
|
||||||
// Get returns a volume by id
|
// Get returns a volume by id
|
||||||
func (v *VolumeServiceOp) Get(volumeID string) (*Volume, *Response, error) {
|
func (v *VolumeServiceOp) Get(volumeID string) (*Volume, *Response, error) {
|
||||||
path := fmt.Sprintf("%s/%s", volumeBasePath, volumeID)
|
path := fmt.Sprintf("%s/%s?include=facility", volumeBasePath, volumeID)
|
||||||
req, err := v.client.NewRequest("GET", path, nil)
|
req, err := v.client.NewRequest("GET", path, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
|
|
Loading…
Reference in New Issue