-
Notifications
You must be signed in to change notification settings - Fork 775
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for deleting an enterprise organization (#1669)
Co-authored-by: Keegan Campbell <[email protected]>
- Loading branch information
1 parent
c968888
commit 872e253
Showing
3 changed files
with
137 additions
and
3 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 |
---|---|---|
@@ -0,0 +1,124 @@ | ||
package github | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/resource" | ||
) | ||
|
||
func TestAccGithubEnterpriseOrganization(t *testing.T) { | ||
|
||
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) | ||
orgName := fmt.Sprintf("tf-acc-test-%s", randomID) | ||
|
||
desc := "Initial org description" | ||
updatedDesc := "Updated org description" | ||
|
||
config := fmt.Sprintf(` | ||
data "github_enterprise" "enterprise" { | ||
slug = "%s" | ||
} | ||
data "github_user" "current" { | ||
username = "" | ||
} | ||
resource "github_enterprise_organization" "org" { | ||
enterprise_id = data.github_enterprise.enterprise.id | ||
name = "%s" | ||
description = "%s" | ||
billing_email = data.github_user.current.email | ||
admin_logins = [ | ||
data.github_user.current.login | ||
] | ||
} | ||
`, testEnterprise, orgName, desc) | ||
|
||
t.Run("creates and updates an enterprise organization without error", func(t *testing.T) { | ||
checks := map[string]resource.TestCheckFunc{ | ||
"before": resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrSet( | ||
"github_enterprise_organization.org", "enterprise_id", | ||
), | ||
resource.TestCheckResourceAttr( | ||
"github_enterprise_organization.org", "name", | ||
orgName, | ||
), | ||
resource.TestCheckResourceAttr( | ||
"github_enterprise_organization.org", "description", | ||
desc, | ||
), | ||
resource.TestCheckResourceAttrSet( | ||
"github_enterprise_organization.org", "billing_email", | ||
), | ||
resource.TestCheckResourceAttr( | ||
"github_enterprise_organization.org", "admin_logins.#", | ||
"1", | ||
), | ||
), | ||
"after": resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr( | ||
"github_enterprise_organization.org", "description", | ||
updatedDesc, | ||
), | ||
), | ||
} | ||
|
||
testCase := func(t *testing.T, mode string) { | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { skipUnlessMode(t, mode) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: config, | ||
Check: checks["before"], | ||
}, | ||
{ | ||
Config: strings.Replace(config, | ||
desc, | ||
updatedDesc, 1), | ||
Check: checks["after"], | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
t.Run("with an enterprise account", func(t *testing.T) { | ||
if isEnterprise != "true" { | ||
t.Skip("Skipping because `ENTERPRISE_ACCOUNT` is not set or set to false") | ||
} | ||
if testEnterprise == "" { | ||
t.Skip("Skipping because `ENTERPRISE_SLUG` is not set") | ||
} | ||
testCase(t, enterprise) | ||
}) | ||
}) | ||
|
||
t.Run("deletes an enterprise organization without error", func(t *testing.T) { | ||
testCase := func(t *testing.T, mode string) { | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { skipUnlessMode(t, mode) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: config, | ||
Destroy: true, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
t.Run("with an enterprise account", func(t *testing.T) { | ||
if isEnterprise != "true" { | ||
t.Skip("Skipping because `ENTERPRISE_ACCOUNT` is not set or set to false") | ||
} | ||
if testEnterprise == "" { | ||
t.Skip("Skipping because `ENTERPRISE_SLUG` is not set") | ||
} | ||
testCase(t, enterprise) | ||
}) | ||
}) | ||
} |
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