Skip to content

Commit

Permalink
fix(test): adjust resource account test
Browse files Browse the repository at this point in the history
  • Loading branch information
delca85 committed Sep 11, 2024
1 parent cd7d085 commit 3cf8344
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions internal/provider/resource_account_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,33 @@ import (
)

func TestAccResourceAccountResource(t *testing.T) {
id := fmt.Sprintf("gcp-test-%d", time.Now().UnixNano())
email := fmt.Sprintf("gpc-myemail-%d@email.com", time.Now().UnixNano())
id := fmt.Sprintf("aws-test-%d", time.Now().UnixNano())
role := fmt.Sprintf("arn:aws:iam::0000000:role/test-role-%d", time.Now().UnixNano())

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
// Create and Read testing
{
Config: testAccResourceAccountResource(id, "gcp-test-1", email),
Config: testAccResourceAccountResource(id, "aws-test-1", role),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("humanitec_resource_account.gcp_test", "id", id),
resource.TestCheckResourceAttr("humanitec_resource_account.gcp_test", "name", "gcp-test-1"),
resource.TestCheckResourceAttr("humanitec_resource_account.aws_test", "id", id),
resource.TestCheckResourceAttr("humanitec_resource_account.aws_test", "name", "aws-test-1"),
),
},
// ImportState testing
{
ResourceName: "humanitec_resource_account.gcp_test",
ResourceName: "humanitec_resource_account.aws_test",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"credentials"},
},
// Update and Read testing
{
Config: testAccResourceAccountResource(id, "gcp-test-2", email),
Config: testAccResourceAccountResource(id, "aws-test-2", role),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("humanitec_resource_account.gcp_test", "name", "gcp-test-2"),
resource.TestCheckResourceAttr("humanitec_resource_account.aws_test", "name", "aws-test-2"),
),
},
// Delete testing automatically occurs in TestCase
Expand All @@ -51,8 +51,8 @@ func TestAccResourceAccountResource(t *testing.T) {
func TestAccResourceAccountResource_DeletedManually(t *testing.T) {
assert := assert.New(t)
ctx := context.Background()
id := fmt.Sprintf("gcp-test-%d", time.Now().UnixNano())
email := fmt.Sprintf("gpc-myemail-%d@email.com", time.Now().UnixNano())
id := fmt.Sprintf("aws-test-%d", time.Now().UnixNano())
role := fmt.Sprintf("arn:aws:iam::0000000:role/test-role-%d", time.Now().UnixNano())

orgID := os.Getenv("HUMANITEC_ORG")
token := os.Getenv("HUMANITEC_TOKEN")
Expand All @@ -74,9 +74,9 @@ func TestAccResourceAccountResource_DeletedManually(t *testing.T) {
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
{
Config: testAccResourceAccountResource(id, "gcp-test-2", email),
Config: testAccResourceAccountResource(id, "aws-test-2", role),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("humanitec_resource_account.gcp_test", "id", id),
resource.TestCheckResourceAttr("humanitec_resource_account.aws_test", "id", id),
func(_ *terraform.State) error {
// Manually delete the resource account via the API
resp, err := client.DeleteResourceAccountWithResponse(ctx, orgID, id)
Expand All @@ -97,16 +97,16 @@ func TestAccResourceAccountResource_DeletedManually(t *testing.T) {
})
}

func testAccResourceAccountResource(id, name, email string) string {
func testAccResourceAccountResource(id, name, role string) string {
return fmt.Sprintf(`
resource "humanitec_resource_account" "gcp_test" {
resource "humanitec_resource_account" "aws_test" {
id = "%s"
name = "%s"
type = "gcp"
type = "aws-role"
credentials = jsonencode({
client_email = "%s"
private_key = "mykey"
aws_role = "%s"
external_id = "test_external_id"
})
}
`, id, name, email)
`, id, name, role)
}

0 comments on commit 3cf8344

Please sign in to comment.