Merge pull request #12686 from hashicorp/f-update-packet-acctest
provider/packet: Update ssh-key resource test to run in parallel better
This commit is contained in:
commit
3daed73c06
|
@ -5,6 +5,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"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"
|
||||||
|
@ -12,19 +13,19 @@ import (
|
||||||
|
|
||||||
func TestAccPacketSSHKey_Basic(t *testing.T) {
|
func TestAccPacketSSHKey_Basic(t *testing.T) {
|
||||||
var key packngo.SSHKey
|
var key packngo.SSHKey
|
||||||
|
rInt := acctest.RandInt()
|
||||||
|
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
CheckDestroy: testAccCheckPacketSSHKeyDestroy,
|
CheckDestroy: testAccCheckPacketSSHKeyDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
{
|
||||||
Config: testAccCheckPacketSSHKeyConfig_basic,
|
Config: testAccCheckPacketSSHKeyConfig_basic(rInt),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckPacketSSHKeyExists("packet_ssh_key.foobar", &key),
|
testAccCheckPacketSSHKeyExists("packet_ssh_key.foobar", &key),
|
||||||
testAccCheckPacketSSHKeyAttributes(&key),
|
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
"packet_ssh_key.foobar", "name", "foobar"),
|
"packet_ssh_key.foobar", "name", fmt.Sprintf("foobar-%d", rInt)),
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
"packet_ssh_key.foobar", "public_key", testAccValidPublicKey),
|
"packet_ssh_key.foobar", "public_key", testAccValidPublicKey),
|
||||||
),
|
),
|
||||||
|
@ -48,15 +49,6 @@ func testAccCheckPacketSSHKeyDestroy(s *terraform.State) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAccCheckPacketSSHKeyAttributes(key *packngo.SSHKey) resource.TestCheckFunc {
|
|
||||||
return func(s *terraform.State) error {
|
|
||||||
if key.Label != "foobar" {
|
|
||||||
return fmt.Errorf("Bad name: %s", key.Label)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func testAccCheckPacketSSHKeyExists(n string, key *packngo.SSHKey) resource.TestCheckFunc {
|
func testAccCheckPacketSSHKeyExists(n string, key *packngo.SSHKey) 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]
|
||||||
|
@ -84,11 +76,13 @@ func testAccCheckPacketSSHKeyExists(n string, key *packngo.SSHKey) resource.Test
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var testAccCheckPacketSSHKeyConfig_basic = fmt.Sprintf(`
|
func testAccCheckPacketSSHKeyConfig_basic(rInt int) string {
|
||||||
|
return fmt.Sprintf(`
|
||||||
resource "packet_ssh_key" "foobar" {
|
resource "packet_ssh_key" "foobar" {
|
||||||
name = "foobar"
|
name = "foobar-%d"
|
||||||
public_key = "%s"
|
public_key = "%s"
|
||||||
}`, testAccValidPublicKey)
|
}`, rInt, testAccValidPublicKey)
|
||||||
|
}
|
||||||
|
|
||||||
var testAccValidPublicKey = strings.TrimSpace(`
|
var testAccValidPublicKey = strings.TrimSpace(`
|
||||||
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCKVmnMOlHKcZK8tpt3MP1lqOLAcqcJzhsvJcjscgVERRN7/9484SOBJ3HSKxxNG5JN8owAjy5f9yYwcUg+JaUVuytn5Pv3aeYROHGGg+5G346xaq3DAwX6Y5ykr2fvjObgncQBnuU5KHWCECO/4h8uWuwh/kfniXPVjFToc+gnkqA+3RKpAecZhFXwfalQ9mMuYGFxn+fwn8cYEApsJbsEmb0iJwPiZ5hjFC8wREuiTlhPHDgkBLOiycd20op2nXzDbHfCHInquEe/gYxEitALONxm0swBOwJZwlTDOB7C6y2dzlrtxr1L59m7pCkWI4EtTRLvleehBoj3u7jB4usR
|
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCKVmnMOlHKcZK8tpt3MP1lqOLAcqcJzhsvJcjscgVERRN7/9484SOBJ3HSKxxNG5JN8owAjy5f9yYwcUg+JaUVuytn5Pv3aeYROHGGg+5G346xaq3DAwX6Y5ykr2fvjObgncQBnuU5KHWCECO/4h8uWuwh/kfniXPVjFToc+gnkqA+3RKpAecZhFXwfalQ9mMuYGFxn+fwn8cYEApsJbsEmb0iJwPiZ5hjFC8wREuiTlhPHDgkBLOiycd20op2nXzDbHfCHInquEe/gYxEitALONxm0swBOwJZwlTDOB7C6y2dzlrtxr1L59m7pCkWI4EtTRLvleehBoj3u7jB4usR
|
||||||
|
|
Loading…
Reference in New Issue