Skip to content

Commit

Permalink
resource_group: add test for members
Browse files Browse the repository at this point in the history
  • Loading branch information
evenh committed Jun 6, 2019
1 parent 192c04b commit 6f0be29
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions azuread/resource_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package azuread

import (
"fmt"
"strings"
"testing"

"github.com/hashicorp/go-uuid"
Expand Down Expand Up @@ -29,6 +30,49 @@ func TestAccAzureADGroup_basic(t *testing.T) {
testCheckAzureADGroupExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "name", fmt.Sprintf("acctest%s", id)),
resource.TestCheckResourceAttrSet(resourceName, "object_id"),
resource.TestCheckNoResourceAttr(resourceName, "members"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccAzureADGroup_members(t *testing.T) {
resourceName := "azuread_group.test"
id, err := uuid.GenerateUUID()
if err != nil {
t.Fatal(err)
}

members := make([]string, 0)

for i := 0; i < 5; i++ {
memberUuid, err := uuid.GenerateUUID()
if err != nil {
t.Fatal(err)
}
members = append(members, "\""+memberUuid+"\"")
}

config := testAccAzureADGroupWithMembers(id, members)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureADGroupDestroy,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
testCheckAzureADGroupExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "name", fmt.Sprintf("acctest%s", id)),
resource.TestCheckResourceAttrSet(resourceName, "object_id"),
resource.TestCheckResourceAttr(resourceName, "members", fmt.Sprintf("[ %s ]", strings.Join(members, ", "))),
),
},
{
Expand Down Expand Up @@ -123,3 +167,12 @@ resource "azuread_group" "test" {
}
`, id)
}

func testAccAzureADGroupWithMembers(id string, members []string) string {
return fmt.Sprintf(`
resource "azuread_group" "test" {
name = "acctest%s"
members = [ %s ]
}
`, id, strings.Join(members, ", "))
}

0 comments on commit 6f0be29

Please sign in to comment.