Skip to content

Commit d60cf4d

Browse files
author
Aaron Welch
committed
update acceptance tests for packet volume, update packngo api client
1 parent 1881465 commit d60cf4d

3 files changed

Lines changed: 31 additions & 24 deletions

File tree

builtin/providers/packet/resource_packet_project_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func testAccCheckPacketProjectDestroy(s *terraform.State) error {
3838
continue
3939
}
4040
if _, _, err := client.Projects.Get(rs.Primary.ID); err == nil {
41-
return fmt.Errorf("Project cstill exists")
41+
return fmt.Errorf("Project still exists")
4242
}
4343
}
4444

builtin/providers/packet/resource_packet_volume_test.go

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package packet
22

33
import (
44
"fmt"
5+
"os"
56
"testing"
67

78
"github.com/hashicorp/terraform/helper/resource"
@@ -12,24 +13,26 @@ import (
1213
func TestAccPacketVolume_Basic(t *testing.T) {
1314
var volume packngo.Volume
1415

16+
project_id := os.Getenv("PACKET_PROJECT_ID")
17+
facility := os.Getenv("PACKET_FACILITY")
18+
1519
resource.Test(t, resource.TestCase{
16-
PreCheck: func() { testAccPreCheck(t) },
20+
PreCheck: testAccPacketVolumePreCheck(t),
1721
Providers: testAccProviders,
1822
CheckDestroy: testAccCheckPacketVolumeDestroy,
1923
Steps: []resource.TestStep{
2024
resource.TestStep{
21-
Config: testAccCheckPacketVolumeConfig_basic,
25+
Config: fmt.Sprintf(testAccCheckPacketVolumeConfig_basic, project_id, facility),
2226
Check: resource.ComposeTestCheckFunc(
2327
testAccCheckPacketVolumeExists("packet_volume.foobar", &volume),
24-
testAccCheckPacketVolumeAttributes(&volume),
25-
resource.TestCheckResourceAttr(
26-
"packet_volume.foobar", "project_id", "foobar"),
2728
resource.TestCheckResourceAttr(
28-
"packet_volume.foobar", "plan", "foobar"),
29+
"packet_volume.foobar", "project_id", project_id),
2930
resource.TestCheckResourceAttr(
30-
"packet_volume.foobar", "facility", "foobar"),
31+
"packet_volume.foobar", "plan", "storage_1"),
3132
resource.TestCheckResourceAttr(
3233
"packet_volume.foobar", "billing_cycle", "hourly"),
34+
resource.TestCheckResourceAttr(
35+
"packet_volume.foobar", "size", "100"),
3336
),
3437
},
3538
},
@@ -44,22 +47,13 @@ func testAccCheckPacketVolumeDestroy(s *terraform.State) error {
4447
continue
4548
}
4649
if _, _, err := client.Volumes.Get(rs.Primary.ID); err == nil {
47-
return fmt.Errorf("Volume cstill exists")
50+
return fmt.Errorf("Volume still exists")
4851
}
4952
}
5053

5154
return nil
5255
}
5356

54-
func testAccCheckPacketVolumeAttributes(volume *packngo.Volume) resource.TestCheckFunc {
55-
return func(s *terraform.State) error {
56-
if volume.Name != "foobar" {
57-
return fmt.Errorf("Bad name: %s", volume.Name)
58-
}
59-
return nil
60-
}
61-
}
62-
6357
func testAccCheckPacketVolumeExists(n string, volume *packngo.Volume) resource.TestCheckFunc {
6458
return func(s *terraform.State) error {
6559
rs, ok := s.RootModule().Resources[n]
@@ -86,10 +80,23 @@ func testAccCheckPacketVolumeExists(n string, volume *packngo.Volume) resource.T
8680
}
8781
}
8882

89-
var testAccCheckPacketVolumeConfig_basic = fmt.Sprintf(`
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+
}
93+
}
94+
95+
const testAccCheckPacketVolumeConfig_basic = `
9096
resource "packet_volume" "foobar" {
91-
project_id = "foobar"
92-
plan = "foobar"
93-
facility = "foobar"
97+
plan = "storage_1"
9498
billing_cycle = "hourly"
95-
}`)
99+
size = 100
100+
project_id = "%s"
101+
facility = "%s"
102+
}`

vendor/github.com/packethost/packngo/volumes.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)