Skip to content

Commit

Permalink
user acc test (#131)
Browse files Browse the repository at this point in the history
  • Loading branch information
jschoombee authored May 23, 2023
1 parent 117d2e7 commit ce8130e
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 0 deletions.
18 changes: 18 additions & 0 deletions internal/acceptance/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,24 @@ func testAccPreCheck(t *testing.T) {
}
}

func testAccPreCheckUser(t *testing.T) {
// You can add code here to run prior to any test case execution, for example assertions
// about the appropriate environment variables being set are common to see in a pre-check
// function.
if v := os.Getenv("WIZ_URL"); v == "" {
t.Fatal("WIZ_URL must be set for acceptance tests")
}
if v := os.Getenv("WIZ_AUTH_CLIENT_ID"); v == "" {
t.Fatal("WIZ_AUTH_CLIENT_ID must be set for acceptance tests")
}
if v := os.Getenv("WIZ_AUTH_CLIENT_SECRET"); v == "" {
t.Fatal("WIZ_AUTH_CLIENT_SECRET must be set for acceptance tests")
}
if v := os.Getenv("WIZ_SMTP_DOMAIN"); v == "" {
t.Fatal("WIZ_SMTP_DOMAIN must be set for wiz_user acceptance tests")
}
}

func testAccPreCheckIntegrationServiceNow(t *testing.T) {
// You can add code here to run prior to any test case execution, for example assertions
// about the appropriate environment variables being set are common to see in a pre-check
Expand Down
67 changes: 67 additions & 0 deletions internal/acceptance/resource_user_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package acceptance

import (
"fmt"
"os"
"testing"

"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
)

func TestAccResourceWizUser_basic(t *testing.T) {
rName := acctest.RandomWithPrefix(ResourcePrefix)
smtpDomain := os.Getenv("WIZ_SMTP_DOMAIN")
resource.UnitTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheckUser(t) },
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: testResourceWizUserBasic(rName, smtpDomain),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
// check that name is correctly set
"wiz_user.foo",
"name",
rName,
),
resource.TestCheckResourceAttr(
// check that email is correctly set
"wiz_user.foo",
"email",
fmt.Sprintf("%s@%s", rName, smtpDomain),
),
resource.TestCheckResourceAttr(
// check that role is set to specified value
"wiz_user.foo",
"role",
"PROJECT_MEMBER",
),
resource.TestCheckResourceAttrSet(
// check for a set assigned project id
"wiz_user.foo",
"assigned_project_ids.0",
),
resource.TestCheckResourceAttrSet(
// check that send_email_invite is set (can be null)
"wiz_user.foo",
"send_email_invite",
),
),
},
},
})
}

func testResourceWizUserBasic(rName string, smtpDomain string) string {
project := uuid.New().String()
return fmt.Sprintf(`
resource "wiz_user" "foo" {
name = "%[1]s"
email = "%[1]s@%s"
role = "PROJECT_MEMBER"
assigned_project_ids = [ "%s" ]
}
`, rName, smtpDomain, project)
}

0 comments on commit ce8130e

Please sign in to comment.