-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: added a couple more tests to test access list edits, email edit…
…s, etc Signed-off-by: Michal Wasilewski <[email protected]>
- Loading branch information
Showing
2 changed files
with
59 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ package spacelift | |
|
||
import ( | ||
"fmt" | ||
"regexp" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" | ||
|
@@ -62,8 +63,7 @@ func TestUserResource(t *testing.T) { | |
}) | ||
}) | ||
|
||
// Note: the api doesn't allow for the username or email to be updated | ||
t.Run("can remove one access", func(t *testing.T) { | ||
t.Run("can edit access list", func(t *testing.T) { | ||
randomUsername := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) | ||
exampleEmail := fmt.Sprintf("%[email protected]", randomUsername) | ||
|
||
|
@@ -90,4 +90,53 @@ func TestUserResource(t *testing.T) { | |
|
||
}) | ||
|
||
t.Run("cannot change email address", func(t *testing.T) { | ||
randomUsername := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) | ||
exampleEmail := fmt.Sprintf("%[email protected]", randomUsername) | ||
|
||
randomUsername2 := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) | ||
exampleEmail2 := fmt.Sprintf("%[email protected]", randomUsername2) | ||
|
||
testSteps(t, []resource.TestStep{ | ||
{ | ||
Config: fmt.Sprintf(userWithOneAccess, exampleEmail, randomUsername), | ||
Check: Resource( | ||
resourceName, | ||
Attribute("invitation_email", Equals(exampleEmail)), | ||
Attribute("username", Equals(randomUsername)), | ||
SetContains("policy", "root", "ADMIN"), | ||
SetDoesNotContain("policy", "legacy"), | ||
), | ||
}, | ||
{ | ||
Config: fmt.Sprintf(userWithOneAccess, exampleEmail2, randomUsername), | ||
ExpectError: regexp.MustCompile(`invitation_email cannot be changed`), | ||
}, | ||
}) | ||
}) | ||
|
||
t.Run("cannot change username", func(t *testing.T) { | ||
randomUsername := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) | ||
exampleEmail := fmt.Sprintf("%[email protected]", randomUsername) | ||
|
||
randomUsername2 := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) | ||
|
||
testSteps(t, []resource.TestStep{ | ||
{ | ||
Config: fmt.Sprintf(userWithOneAccess, exampleEmail, randomUsername), | ||
Check: Resource( | ||
resourceName, | ||
Attribute("invitation_email", Equals(exampleEmail)), | ||
Attribute("username", Equals(randomUsername)), | ||
SetContains("policy", "root", "ADMIN"), | ||
SetDoesNotContain("policy", "legacy"), | ||
), | ||
}, | ||
{ | ||
Config: fmt.Sprintf(userWithOneAccess, exampleEmail, randomUsername2), | ||
ExpectError: regexp.MustCompile(`username cannot be changed`), | ||
}, | ||
}) | ||
}) | ||
|
||
} |