Skip to content

Commit

Permalink
test: user group resource
Browse files Browse the repository at this point in the history
Signed-off-by: Michal Wasilewski <[email protected]>
  • Loading branch information
mwasilew2 committed Oct 6, 2023
1 parent b918ec1 commit 1b4447d
Showing 1 changed file with 97 additions and 0 deletions.
97 changes: 97 additions & 0 deletions spacelift/resource_user_group_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package spacelift

import (
"fmt"
"testing"

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

. "github.com/spacelift-io/terraform-provider-spacelift/spacelift/internal/testhelpers"
)

var withOneAccess = `
resource "spacelift_user_group" "test" {
name = "%s"
access {
space_id = "root"
level = "ADMIN"
}
}
`

var withTwoAccesses = `
resource "spacelift_user_group" "test" {
name = "%s"
access {
space_id = "root"
level = "ADMIN"
}
access {
space_id = "legacy"
level = "READ"
}
}
`

func TestUserGroupResource(t *testing.T) {
const resourceName = "spacelift_user_group.test"

t.Run("creates and updates a user group without an error", func(t *testing.T) {
oldName := "old name"
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)

testSteps(t, []resource.TestStep{
{
Config: fmt.Sprintf(withOneAccess, oldName),
Check: Resource(
resourceName,
Attribute("name", Equals(oldName)),
SetContains("access", "root"),
SetContains("access", "ADMIN"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
{
Config: fmt.Sprintf(withOneAccess, randomID),
Check: Resource(
resourceName,
Attribute("name", Equals(randomID)),
),
},
})
})

t.Run("can remove one access", func(t *testing.T) {
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)

testSteps(t, []resource.TestStep{
{
Config: fmt.Sprintf(withTwoAccesses, randomID),
Check: Resource(
resourceName,
Attribute("name", Equals(randomID)),
SetContains("access", "root"),
SetContains("access", "ADMIN"),
SetContains("access", "legacy"),
SetContains("access", "READ"),
),
},
{
Config: fmt.Sprintf(withOneAccess, randomID),
Check: Resource(
resourceName,
SetContains("access", "root"),
SetContains("access", "ADMIN"),
SetDoesNotContain("access", "legacy"),
SetDoesNotContain("access", "READ"),
),
},
})
})

}

0 comments on commit 1b4447d

Please sign in to comment.