-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* add optional setting to stop maintaing team members, refs #65 Signed-off-by: Arnold Bechtoldt <[email protected]>
- Loading branch information
Showing
4 changed files
with
146 additions
and
4 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
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 |
---|---|---|
|
@@ -74,6 +74,108 @@ func TestAccOpsGenieTeam_basic(t *testing.T) { | |
}) | ||
} | ||
|
||
func TestAccOpsGenieTeam_basicNoMember(t *testing.T) { | ||
randomTeam := acctest.RandString(6) | ||
randomUser := acctest.RandString(6) | ||
config := testAccOpsGenieTeam_basicNoMember(randomUser, randomTeam) | ||
|
||
resource.Test(t, resource.TestCase{ | ||
Providers: testAccProviders, | ||
CheckDestroy: testCheckOpsGenieTeamDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: config, | ||
Check: resource.ComposeTestCheckFunc( | ||
testCheckOpsGenieTeamExists("opsgenie_team.test"), | ||
testEmptyMemberList("opsgenie_team.test"), | ||
addTeamMembers("opsgenie_team.test", "opsgenie_user.test"), | ||
), | ||
}, | ||
{ | ||
Config: config, | ||
Check: resource.ComposeTestCheckFunc( | ||
testEmptyMemberList("opsgenie_team.test"), | ||
removeAllTeamMembers("opsgenie_team.test"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testEmptyMemberList(teamName string) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
teamResource, ok := s.RootModule().Resources[teamName] | ||
if !ok { | ||
return fmt.Errorf("Not found: %s", teamName) | ||
} | ||
|
||
if len(teamResource.Primary.Attributes["member"]) > 0 { | ||
return fmt.Errorf("member list in state of resource %q is unexpectely not empty", teamName) | ||
} | ||
|
||
return nil | ||
} | ||
} | ||
|
||
func addTeamMembers(teamName string, userName string) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
teamResource, ok := s.RootModule().Resources[teamName] | ||
if !ok { | ||
return fmt.Errorf("Not found: %s", teamName) | ||
} | ||
|
||
userResource, ok := s.RootModule().Resources[userName] | ||
if !ok { | ||
return fmt.Errorf("Not found: %s", userName) | ||
} | ||
|
||
updateRequest := team.UpdateTeamRequest{ | ||
Id: teamResource.Primary.Attributes["id"], | ||
Name: teamResource.Primary.Attributes["name"], | ||
Description: teamResource.Primary.Attributes["description"], | ||
Members: []team.Member{ | ||
{ | ||
User: team.User{ID: userResource.Primary.ID}, | ||
}, | ||
}, | ||
} | ||
|
||
return updateTeamMembers(s, updateRequest) | ||
} | ||
} | ||
|
||
func removeAllTeamMembers(teamName string) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
teamResource, ok := s.RootModule().Resources[teamName] | ||
if !ok { | ||
return fmt.Errorf("Not found: %s", teamName) | ||
} | ||
|
||
updateRequest := team.UpdateTeamRequest{ | ||
Id: teamResource.Primary.Attributes["id"], | ||
Name: teamResource.Primary.Attributes["name"], | ||
Description: teamResource.Primary.Attributes["description"], | ||
Members: []team.Member{}, | ||
} | ||
|
||
return updateTeamMembers(s, updateRequest) | ||
} | ||
} | ||
|
||
func updateTeamMembers(s *terraform.State, updateRequest team.UpdateTeamRequest) error { | ||
client, err := team.NewClient(testAccProvider.Meta().(*OpsgenieClient).client.Config) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
_, err = client.Update(context.Background(), &updateRequest) | ||
if err != nil { | ||
return fmt.Errorf("error updating team %q with members %q", updateRequest.Name, updateRequest.Members) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func TestAccOpsGenieTeam_complete(t *testing.T) { | ||
randomTeam := acctest.RandString(6) | ||
randomUser := acctest.RandString(6) | ||
|
@@ -156,6 +258,22 @@ resource "opsgenie_team" "test" { | |
`, rString) | ||
} | ||
|
||
func testAccOpsGenieTeam_basicNoMember(randomUser, rString string) string { | ||
return fmt.Sprintf(` | ||
resource "opsgenie_team" "test" { | ||
name = "genieteam-%s" | ||
description = "This team deals with all the things" | ||
ignore_members = true | ||
depends_on = [opsgenie_user.test] # Just a hack for the test to destroy resources in the right order | ||
} | ||
resource "opsgenie_user" "test" { | ||
username = "genietest-%[email protected]" | ||
full_name = "Acceptance Test User" | ||
role = "User" | ||
} | ||
`, randomUser, rString) | ||
} | ||
|
||
func testAccOpsGenieTeam_complete(randomUser, randomTeam string) string { | ||
return fmt.Sprintf(` | ||
resource "opsgenie_user" "test" { | ||
|
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