-
Notifications
You must be signed in to change notification settings - Fork 741
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add acceptance test for
github_app_installation_repository
- Loading branch information
Jeremy Udit
committed
Mar 23, 2021
1 parent
6390fc1
commit eaaaf65
Showing
1 changed file
with
75 additions
and
0 deletions.
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
github/resource_github_app_installation_repository_test.go
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,75 @@ | ||
package github | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/resource" | ||
) | ||
|
||
func TestAccGithubAppInstallationRepository(t *testing.T) { | ||
|
||
const APP_INSTALLATION_ID = "APP_INSTALLATION_ID" | ||
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) | ||
installation_id, exists := os.LookupEnv(APP_INSTALLATION_ID) | ||
|
||
t.Run("installs an app to a repository", func(t *testing.T) { | ||
|
||
if !exists { | ||
t.Skipf("%s environment variable is missing", APP_INSTALLATION_ID) | ||
} | ||
|
||
config := fmt.Sprintf(` | ||
resource "github_repository" "test" { | ||
name = "tf-acc-test-%s" | ||
auto_init = true | ||
} | ||
resource "github_app_installation_repository" "test" { | ||
# The installation id of the app (in the organization). | ||
installation_id = "%s" | ||
repository = github_repository.test.name | ||
} | ||
`, randomID, installation_id) | ||
|
||
check := resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrSet( | ||
"github_app_installation_repository.test", "installation_id", | ||
), | ||
resource.TestCheckResourceAttrSet( | ||
"github_app_installation_repository.test", "repo_id", | ||
), | ||
) | ||
|
||
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: check, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
t.Run("with an anonymous account", func(t *testing.T) { | ||
t.Skip("anonymous account not supported for this operation") | ||
}) | ||
|
||
t.Run("with an individual account", func(t *testing.T) { | ||
t.Skip("individual account not supported for this operation") | ||
}) | ||
|
||
t.Run("with an organization account", func(t *testing.T) { | ||
testCase(t, organization) | ||
}) | ||
|
||
}) | ||
|
||
} |