Skip to content

Commit

Permalink
acc test user groups (#9)
Browse files Browse the repository at this point in the history
* bump deps

* markdown lint

* string format

* user_group resource acc test
  • Loading branch information
gypsydiver authored and daniellohausen committed Feb 18, 2019
1 parent ed11207 commit 3e4c1c3
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 60 deletions.
88 changes: 44 additions & 44 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ make build

If you're building the provider, follow the instructions to [install it as a plugin.](https://www.terraform.io/docs/plugins/basics.html#installing-a-plugin) After placing it into your plugins directory, run `terraform init` to initialize it.

## Tips
* When importing a resource, you need the Jumpcloud ID. It can either be retrieved via the API or through the UI : When selecting a resource, the ID is part of URL.
## Tips

- When importing a resource, you need the Jumpcloud ID. It can either be retrieved via the API or through the UI : When selecting a resource, the ID is part of URL.
44 changes: 40 additions & 4 deletions jumpcloud/resource_user_group_test.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,55 @@
package jumpcloud

import (
"fmt"
"net/http"
"net/http/httptest"
"testing"

jcapiv2 "github.com/TheJumpCloud/jcapi-go/v2"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
)

func TestAccUserGroup(t *testing.T) {
rName := acctest.RandStringFromCharSet(10, acctest.CharSetAlpha)
posixName := acctest.RandStringFromCharSet(10, acctest.CharSetAlpha)
gid := acctest.RandIntRange(1, 1000)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: nil,
Steps: []resource.TestStep{
{
Config: testAccUserGroup(rName, gid, posixName),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("jumpcloud_user_group.test_group", "name", rName),
resource.TestCheckResourceAttr("jumpcloud_user_group.test_group",
"attributes.posix_groups", fmt.Sprintf("%d:%s", gid, posixName)),
),
},
},
})
}

func testAccUserGroup(name string, gid int, posixName string) string {
return fmt.Sprintf(`
resource "jumpcloud_user_group" "test_group" {
name = "%s"
attributes {
posix_groups = "%d:%s"
}
}`, name, gid, posixName,
)
}

func TestResourceUserGroup(t *testing.T) {
suite.Run(t, new(ResourceUserGroupSuite))
}

type ResourceUserGroupSuite struct {
suite.Suite
A *assert.Assertions
Expand Down Expand Up @@ -49,7 +89,3 @@ func (s *ResourceUserGroupSuite) TestTrueUserGroupRead() {
testServer.Close()
}
}

func TestResourceUserGroup(t *testing.T) {
suite.Run(t, new(ResourceUserGroupSuite))
}
17 changes: 7 additions & 10 deletions jumpcloud/resource_user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,12 @@ func testAccPreCheck(t *testing.T) {

func testAccUser(name string) string {
return fmt.Sprintf(`
resource "jumpcloud_user" "test_user" {
username = "%s"
email = "%[email protected]"
firstname = "Firstname"
lastname = "Lastname"
enable_mfa = true
}
`,
name, name,
resource "jumpcloud_user" "test_user" {
username = "%s"
email = "%[email protected]"
firstname = "Firstname"
lastname = "Lastname"
enable_mfa = true
}`, name, name,
)
}

0 comments on commit 3e4c1c3

Please sign in to comment.