Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cheelim1 committed Apr 21, 2023
1 parent f0050d7 commit 6129e9f
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 0 deletions.
68 changes: 68 additions & 0 deletions jumpcloud/data_source_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package jumpcloud

import (
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
// "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

//Make sure to replace "your-jumpcloud-api-key" with your actual JumpCloud API key.
const testConfig = `
provider "jumpcloud" {
# Configure your JumpCloud API key
api_key = "your-jumpcloud-api-key"
}
data "jumpcloud_user" "test" {
email = "[email protected]"
}
`

func TestAccDataSourceJumpCloudUser(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: nil,
Steps: []resource.TestStep{
{
Config: testConfig,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("data.jumpcloud_user.test", "id"),
resource.TestCheckResourceAttr("data.jumpcloud_user.test", "email", "[email protected]"),
),
},
},
})
}

// // func TestAccDataSourceJumpCloudUser_basic(t *testing.T) {
// // userEmail := "<existing-user-email>" // Replace this with an existing user's email address
// // resourceName := "data.jumpcloud_user.test"

// // resource.Test(t, resource.TestCase{
// // PreCheck: func() { testAccPreCheck(t) },
// // Providers: testAccProviders,
// // Steps: []resource.TestStep{
// // {
// // Config: testAccDataSourceJumpCloudUserConfig(userEmail),
// // Check: resource.ComposeTestCheckFunc(
// // resource.TestCheckResourceAttrSet(resourceName, "id"),
// // ),
// // },
// // },
// // })
// // }

// // func testAccDataSourceJumpCloudUserConfig(userEmail string) string {
// // return acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum) + `

// // provider "jumpcloud" {
// // api_key = "` + os.Getenv("JUMPCLOUD_API_KEY") + `"
// // }

// // data "jumpcloud_user" "test" {
// // email = "` + userEmail + `"
// // }
// // `
// // }
45 changes: 45 additions & 0 deletions jumpcloud/resource_user_group_association_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package jumpcloud

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
)

func TestAccUserGroupAssociation(t *testing.T) {
randSuffix := acctest.RandStringFromCharSet(10, acctest.CharSetAlpha)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: nil,
Steps: []resource.TestStep{
{
Config: testUserGroupAssocConfig(randSuffix),
Check: resource.TestCheckResourceAttrSet("jumpcloud_user_group_association.test_association",
"group_id"),
},
},
})
}

func testUserGroupAssocConfig(randSuffix string) string {
return fmt.Sprintf(`
resource "jumpcloud_application" "test_application" {
display_name = "test_aws_account_%s"
sso_url = "https://sso.jumpcloud.com/saml2/example-application-%s"
}
resource "jumpcloud_user_group" "test_group" {
name = "testgroup_%s"
}
resource "jumpcloud_user_group_association" "test_association" {
object_id = jumpcloud_application.test_application.id
group_id = jumpcloud_user_group.test_group.id
type = "application"
}
`, randSuffix, randSuffix, randSuffix)
}

0 comments on commit 6129e9f

Please sign in to comment.