Skip to content

Commit

Permalink
Add GHES Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy Udit committed Sep 4, 2020
1 parent 63f5c02 commit 88d0215
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 14 deletions.
3 changes: 2 additions & 1 deletion github/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (c *Config) NewRESTClient(client *http.Client) (*github.Client, error) {
}

if uv3.String() != "https://api.github.com/" {
uv3.Path = uv3.Path + "v3/"
uv3.Path = uv3.Path + "api/v3/"
}

v3client, err := github.NewEnterpriseClient(uv3.String(), "", client)
Expand All @@ -93,6 +93,7 @@ func (c *Config) NewRESTClient(client *http.Client) (*github.Client, error) {
}

func (c *Config) ConfigureOwner(owner *Owner) (*Owner, error) {

ctx := context.Background()
owner.name = c.Owner
if owner.name == "" {
Expand Down
21 changes: 21 additions & 0 deletions github/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,25 @@ func TestAccConfigMeta(t *testing.T) {

})

t.Run("manages individual resources for a GHES deployment", func(t *testing.T) {

config := Config{
Token: testTokenGHES,
BaseURL: testBaseURLGHES,
Anonymous: false,
}
meta, err := config.Meta()
if err != nil {
t.Fatalf("failed to return meta without error: %s", err.Error())
}

ctx := context.Background()
client := meta.(*Owner).v3client
_, _, err = client.APIMeta(ctx)
if err != nil {
t.Fatalf("failed to validate returned client without error: %s", err.Error())
}

})

}
62 changes: 49 additions & 13 deletions github/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,6 @@ func TestAccProviderConfigure(t *testing.T) {

username := "hashibot"
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
},
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Expand Down Expand Up @@ -126,14 +123,16 @@ func TestAccProviderConfigure(t *testing.T) {

individualConfiguration := fmt.Sprintf(`
provider "github" {
owner = "%s"
token = "%s"
}
data "github_user" "test" { username = "%s" }
`, testOwner, testToken, testOwner)
`,
os.Getenv("GITHUB_TOKEN"),
os.Getenv("GITHUB_ORGANIZATION"),
)

individualCheck := resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("data.github_user.test", "name"),
resource.TestCheckResourceAttrSet("data.github_user.test", "username"),
)

resource.Test(t, resource.TestCase{
Expand All @@ -142,11 +141,7 @@ func TestAccProviderConfigure(t *testing.T) {
"GITHUB_TOKEN",
"GITHUB_OWNER",
}
for _, variable := range requiredEnvironmentVariables {
if v := os.Getenv(variable); v == "" {
t.Fatal(variable + " must be set for acceptance tests")
}
}
testAccPreCheckEnvironment(t, requiredEnvironmentVariables)
},
Providers: testAccProviders,
Steps: []resource.TestStep{
Expand All @@ -167,7 +162,11 @@ func TestAccProviderConfigure(t *testing.T) {
token = "%s"
}
data "github_organization" "test" { name = "%s" }
`, testOrganization, testToken, testOrganization)
`,
os.Getenv("GITHUB_ORGANIZATION"),
os.Getenv("GITHUB_TOKEN"),
os.Getenv("GITHUB_ORGANIZATION"),
)

organizationCheck := resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("data.github_organization.test", "plan"),
Expand All @@ -176,8 +175,45 @@ func TestAccProviderConfigure(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() {
requiredEnvironmentVariables := []string{
"GITHUB_TOKEN",
"GITHUB_ORGANIZATION",
"GITHUB_TOKEN",
}
testAccPreCheckEnvironment(t, requiredEnvironmentVariables)
},
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: organizationConfiguration,
Check: organizationCheck,
},
},
})
})

t.Run("can be configured with a GHES deployment", func(t *testing.T) {

organizationConfiguration := fmt.Sprintf(`
provider "github" {
base_url = "%s"
token = "%s"
}
data "github_organization" "test" { name = "%s" }
`,
os.Getenv("GHES_BASE_URL"),
os.Getenv("GHES_TOKEN"),
os.Getenv("GHES_ORGANIZATION"),
)

organizationCheck := resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("data.github_organization.test", "plan"),
)

resource.Test(t, resource.TestCase{
PreCheck: func() {
requiredEnvironmentVariables := []string{
"GHES_TOKEN",
"GHES_BASE_URL",
"GHES_ORGANIZATION",
}
testAccPreCheckEnvironment(t, requiredEnvironmentVariables)
},
Expand Down
3 changes: 3 additions & 0 deletions github/provider_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ var testOrganization string = os.Getenv("GITHUB_ORGANIZATION")
var testOwner string = os.Getenv("GITHUB_OWNER")
var testToken string = os.Getenv("GITHUB_TOKEN")

var testTokenGHES string = os.Getenv("GHES_TOKEN")
var testBaseURLGHES string = os.Getenv("GHES_BASE_URL")

func testAccPreCheckEnvironment(t *testing.T, requiredEnvironmentVariables []string) {
for _, variable := range requiredEnvironmentVariables {
if v := os.Getenv(variable); v == "" {
Expand Down

0 comments on commit 88d0215

Please sign in to comment.