-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🥢 import ssh key by fingerprint, make tests faster
- Loading branch information
1 parent
ffcadb7
commit d42d5c6
Showing
11 changed files
with
150 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
TF_ACC=1 | ||
BINARYLANE_API_TOKEN= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"go.testEnvFile": "${workspaceFolder}/.env", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,11 +7,13 @@ import ( | |
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-testing/terraform" | ||
) | ||
|
||
func TestSshKeyResource(t *testing.T) { | ||
publicKey := GeneratePublicKey(t) | ||
resource.Test(t, resource.TestCase{ | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, | ||
Steps: []resource.TestStep{ | ||
// Create and Read testing | ||
|
@@ -43,13 +45,19 @@ data "binarylane_ssh_key" "test" { | |
), | ||
}, | ||
// ImportState testing | ||
// TODO | ||
// { | ||
// ResourceName: "binarylane_ssh_key.test", | ||
// ImportState: true, | ||
// ImportStateVerify: true, | ||
// ImportStateVerifyIgnore: []string{}, // nothing to ignore | ||
// }, | ||
{ | ||
ResourceName: "binarylane_ssh_key.test", | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
ImportStateVerifyIgnore: []string{}, // nothing to ignore | ||
}, | ||
{ | ||
ResourceName: "binarylane_ssh_key.test", | ||
ImportStateIdFunc: ImportByFingerprint, | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
ImportStateVerifyIgnore: []string{}, // nothing to ignore | ||
}, | ||
// TODO: Update and Read testing | ||
// { | ||
// Config: providerConfig + ` | ||
|
@@ -73,11 +81,28 @@ data "binarylane_ssh_key" "test" { | |
func GeneratePublicKey(t *testing.T) string { | ||
t.Helper() | ||
|
||
_, pub, err := ed25519.GenerateKey(nil) | ||
pub, _, err := ed25519.GenerateKey(nil) | ||
if err != nil { | ||
t.Fatalf("failed to generate key: %v", err) | ||
} | ||
|
||
encoded := base64.StdEncoding.EncodeToString(pub) | ||
return fmt.Sprintf("ssh-ed25519 %s [email protected]", encoded) | ||
} | ||
|
||
func ImportByFingerprint(state *terraform.State) (fingerprint string, err error) { | ||
resourceName := "binarylane_ssh_key.test" | ||
var rawState map[string]string | ||
for _, m := range state.Modules { | ||
if len(m.Resources) > 0 { | ||
if v, ok := m.Resources[resourceName]; ok { | ||
rawState = v.Primary.Attributes | ||
} | ||
} | ||
} | ||
if rawState == nil { | ||
return "", fmt.Errorf("resource not found: %s", resourceName) | ||
} | ||
|
||
return rawState["fingerprint"], nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters