diff --git a/github/resource_github_repository_collaborator_test.go b/github/resource_github_repository_collaborator_test.go index b8ab1b35ed..c49f3b595f 100644 --- a/github/resource_github_repository_collaborator_test.go +++ b/github/resource_github_repository_collaborator_test.go @@ -14,8 +14,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/terraform" ) -const expectedPermission string = "admin" - func TestAccGithubRepositoryCollaborator_basic(t *testing.T) { if testCollaborator == "" { t.Skip("Skipping because `GITHUB_TEST_COLLABORATOR` is not set") @@ -24,17 +22,49 @@ func TestAccGithubRepositoryCollaborator_basic(t *testing.T) { rn := "github_repository_collaborator.test_repo_collaborator" repoName := fmt.Sprintf("tf-acc-test-collab-%s", acctest.RandString(5)) + permissionAdmin := "admin" + permissionTriage := "triage" + permissionPush := "push" + permissionPull := "pull" + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckGithubRepositoryCollaboratorDestroy, Steps: []resource.TestStep{ { - Config: testAccGithubRepositoryCollaboratorConfig(repoName, testCollaborator), + Config: testAccGithubRepositoryCollaboratorConfig(repoName, testCollaborator, permissionPull), Check: resource.ComposeTestCheckFunc( testAccCheckGithubRepositoryCollaboratorExists(rn), - testAccCheckGithubRepositoryCollaboratorPermission(rn), - resource.TestCheckResourceAttr(rn, "permission", expectedPermission), + testAccCheckGithubRepositoryCollaboratorPermission(rn, permissionPull), + resource.TestCheckResourceAttr(rn, "permission", permissionPull), + resource.TestMatchResourceAttr(rn, "invitation_id", regexp.MustCompile(`^[0-9]+$`)), + ), + }, + { + Config: testAccGithubRepositoryCollaboratorConfig(repoName, testCollaborator, permissionPush), + Check: resource.ComposeTestCheckFunc( + testAccCheckGithubRepositoryCollaboratorExists(rn), + testAccCheckGithubRepositoryCollaboratorPermission(rn, permissionPush), + resource.TestCheckResourceAttr(rn, "permission", permissionPush), + resource.TestMatchResourceAttr(rn, "invitation_id", regexp.MustCompile(`^[0-9]+$`)), + ), + }, + { + Config: testAccGithubRepositoryCollaboratorConfig(repoName, testCollaborator, permissionAdmin), + Check: resource.ComposeTestCheckFunc( + testAccCheckGithubRepositoryCollaboratorExists(rn), + testAccCheckGithubRepositoryCollaboratorPermission(rn, permissionAdmin), + resource.TestCheckResourceAttr(rn, "permission", permissionAdmin), + resource.TestMatchResourceAttr(rn, "invitation_id", regexp.MustCompile(`^[0-9]+$`)), + ), + }, + { + Config: testAccGithubRepositoryCollaboratorConfig(repoName, testCollaborator, permissionTriage), + Check: resource.ComposeTestCheckFunc( + testAccCheckGithubRepositoryCollaboratorExists(rn), + testAccCheckGithubRepositoryCollaboratorPermission(rn, permissionTriage), + resource.TestCheckResourceAttr(rn, "permission", permissionTriage), resource.TestMatchResourceAttr(rn, "invitation_id", regexp.MustCompile(`^[0-9]+$`)), ), }, @@ -58,6 +88,8 @@ func TestAccGithubRepositoryCollaborator_caseInsensitive(t *testing.T) { var origInvitation github.RepositoryInvitation var otherInvitation github.RepositoryInvitation + expectedPermission := "maintain" + otherCase := flipUsernameCase(testCollaborator) if testCollaborator == otherCase { @@ -70,13 +102,13 @@ func TestAccGithubRepositoryCollaborator_caseInsensitive(t *testing.T) { CheckDestroy: testAccCheckGithubRepositoryCollaboratorDestroy, Steps: []resource.TestStep{ { - Config: testAccGithubRepositoryCollaboratorConfig(repoName, testCollaborator), + Config: testAccGithubRepositoryCollaboratorConfig(repoName, testCollaborator, expectedPermission), Check: resource.ComposeTestCheckFunc( testAccCheckGithubRepositoryCollaboratorInvited(repoName, testCollaborator, &origInvitation), ), }, { - Config: testAccGithubRepositoryCollaboratorConfig(repoName, otherCase), + Config: testAccGithubRepositoryCollaboratorConfig(repoName, otherCase, expectedPermission), Check: resource.ComposeTestCheckFunc( testAccCheckGithubRepositoryCollaboratorInvited(repoName, otherCase, &otherInvitation), resource.TestCheckResourceAttr(rn, "username", testCollaborator), @@ -162,7 +194,7 @@ func testAccCheckGithubRepositoryCollaboratorExists(n string) resource.TestCheck } } -func testAccCheckGithubRepositoryCollaboratorPermission(n string) resource.TestCheckFunc { +func testAccCheckGithubRepositoryCollaboratorPermission(n, permission string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -194,8 +226,8 @@ func testAccCheckGithubRepositoryCollaboratorPermission(n string) resource.TestC return err } - if permName != expectedPermission { - return fmt.Errorf("Expected permission %s on repository collaborator, actual permission %s", expectedPermission, permName) + if permName != permission { + return fmt.Errorf("Expected permission %s on repository collaborator, actual permission %s", permission, permName) } return nil @@ -206,7 +238,7 @@ func testAccCheckGithubRepositoryCollaboratorPermission(n string) resource.TestC } } -func testAccGithubRepositoryCollaboratorConfig(repoName, username string) string { +func testAccGithubRepositoryCollaboratorConfig(repoName, username, permission string) string { return fmt.Sprintf(` resource "github_repository" "test" { name = "%s" @@ -217,7 +249,7 @@ resource "github_repository_collaborator" "test_repo_collaborator" { username = "%s" permission = "%s" } -`, repoName, username, expectedPermission) +`, repoName, username, permission) } func testAccCheckGithubRepositoryCollaboratorInvited(repoName, username string, invitation *github.RepositoryInvitation) resource.TestCheckFunc { diff --git a/github/util_permissions.go b/github/util_permissions.go index 0eb8b75543..eefcf8bb84 100644 --- a/github/util_permissions.go +++ b/github/util_permissions.go @@ -49,6 +49,10 @@ func getInvitationPermission(i *github.RepositoryInvitation) (string, error) { return pushPermission, nil } else if permissions == adminPermission { return adminPermission, nil + } else if *i.Permissions == maintainPermission { + return maintainPermission, nil + } else if *i.Permissions == triagePermission { + return triagePermission, nil } return "", fmt.Errorf("unexpected permission value: %v", permissions) diff --git a/website/docs/r/repository_collaborator.html.markdown b/website/docs/r/repository_collaborator.html.markdown index eea8e36428..3871e39d73 100644 --- a/website/docs/r/repository_collaborator.html.markdown +++ b/website/docs/r/repository_collaborator.html.markdown @@ -41,7 +41,7 @@ The following arguments are supported: * `repository` - (Required) The GitHub repository * `username` - (Required) The user to add to the repository as a collaborator. * `permission` - (Optional) The permission of the outside collaborator for the repository. - Must be one of `pull`, `push`, or `admin`. Defaults to `push`. + Must be one of `pull`, `push`, `maintain`, `triage` or `admin`. Defaults to `push`. ## Attribute Reference