@@ -5,26 +5,27 @@ import (
55 "strings"
66 "testing"
77
8+ "github.com/hashicorp/terraform/helper/acctest"
89 "github.com/hashicorp/terraform/helper/resource"
910 "github.com/hashicorp/terraform/terraform"
1011 "github.com/packethost/packngo"
1112)
1213
1314func TestAccPacketSSHKey_Basic (t * testing.T ) {
1415 var key packngo.SSHKey
16+ rInt := acctest .RandInt ()
1517
1618 resource .Test (t , resource.TestCase {
1719 PreCheck : func () { testAccPreCheck (t ) },
1820 Providers : testAccProviders ,
1921 CheckDestroy : testAccCheckPacketSSHKeyDestroy ,
2022 Steps : []resource.TestStep {
21- resource. TestStep {
22- Config : testAccCheckPacketSSHKeyConfig_basic ,
23+ {
24+ Config : testAccCheckPacketSSHKeyConfig_basic ( rInt ) ,
2325 Check : resource .ComposeTestCheckFunc (
2426 testAccCheckPacketSSHKeyExists ("packet_ssh_key.foobar" , & key ),
25- testAccCheckPacketSSHKeyAttributes (& key ),
2627 resource .TestCheckResourceAttr (
27- "packet_ssh_key.foobar" , "name" , "foobar" ),
28+ "packet_ssh_key.foobar" , "name" , fmt . Sprintf ( "foobar-%d" , rInt ) ),
2829 resource .TestCheckResourceAttr (
2930 "packet_ssh_key.foobar" , "public_key" , testAccValidPublicKey ),
3031 ),
@@ -48,15 +49,6 @@ func testAccCheckPacketSSHKeyDestroy(s *terraform.State) error {
4849 return nil
4950}
5051
51- func testAccCheckPacketSSHKeyAttributes (key * packngo.SSHKey ) resource.TestCheckFunc {
52- return func (s * terraform.State ) error {
53- if key .Label != "foobar" {
54- return fmt .Errorf ("Bad name: %s" , key .Label )
55- }
56- return nil
57- }
58- }
59-
6052func testAccCheckPacketSSHKeyExists (n string , key * packngo.SSHKey ) resource.TestCheckFunc {
6153 return func (s * terraform.State ) error {
6254 rs , ok := s .RootModule ().Resources [n ]
@@ -84,11 +76,13 @@ func testAccCheckPacketSSHKeyExists(n string, key *packngo.SSHKey) resource.Test
8476 }
8577}
8678
87- var testAccCheckPacketSSHKeyConfig_basic = fmt .Sprintf (`
79+ func testAccCheckPacketSSHKeyConfig_basic (rInt int ) string {
80+ return fmt .Sprintf (`
8881resource "packet_ssh_key" "foobar" {
89- name = "foobar"
82+ name = "foobar-%d "
9083 public_key = "%s"
91- }` , testAccValidPublicKey )
84+ }` , rInt , testAccValidPublicKey )
85+ }
9286
9387var testAccValidPublicKey = strings .TrimSpace (`
9488ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCKVmnMOlHKcZK8tpt3MP1lqOLAcqcJzhsvJcjscgVERRN7/9484SOBJ3HSKxxNG5JN8owAjy5f9yYwcUg+JaUVuytn5Pv3aeYROHGGg+5G346xaq3DAwX6Y5ykr2fvjObgncQBnuU5KHWCECO/4h8uWuwh/kfniXPVjFToc+gnkqA+3RKpAecZhFXwfalQ9mMuYGFxn+fwn8cYEApsJbsEmb0iJwPiZ5hjFC8wREuiTlhPHDgkBLOiycd20op2nXzDbHfCHInquEe/gYxEitALONxm0swBOwJZwlTDOB7C6y2dzlrtxr1L59m7pCkWI4EtTRLvleehBoj3u7jB4usR
0 commit comments