Skip to content

Commit

Permalink
add acceptance test for github_app_installation_repository
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy Udit committed Mar 23, 2021
1 parent 6390fc1 commit eaaaf65
Showing 1 changed file with 75 additions and 0 deletions.
75 changes: 75 additions & 0 deletions github/resource_github_app_installation_repository_test.go
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)
})

})

}

0 comments on commit eaaaf65

Please sign in to comment.