Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions github/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ func Provider() *schema.Provider {
p := &schema.Provider{
Schema: map[string]*schema.Schema{
"token": {
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("GITHUB_TOKEN", nil),
Description: descriptions["token"],
ConflictsWith: []string{"app_auth"},
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("GITHUB_TOKEN", nil),
Description: descriptions["token"],
// ConflictsWith: []string{"app_auth"}, // TODO: Enable as part of v7.
},
"owner": {
Type: schema.TypeString,
Expand Down Expand Up @@ -94,11 +94,11 @@ func Provider() *schema.Provider {
Description: descriptions["parallel_requests"],
},
"app_auth": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Description: descriptions["app_auth"],
ConflictsWith: []string{"token"},
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Description: descriptions["app_auth"],
// ConflictsWith: []string{"token"}, // TODO: Enable as part of v7.
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Expand Down
56 changes: 29 additions & 27 deletions github/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestProvider(t *testing.T) {
}

func TestAccProviderConfigure(t *testing.T) {
t.Run("can be configured to run anonymously", func(t *testing.T) {
t.Run("can_be_configured_to_run_anonymously", func(t *testing.T) {
config := `
provider "github" {
}
Expand All @@ -71,10 +71,36 @@ func TestAccProviderConfigure(t *testing.T) {
})
})

t.Run("can_be_configured_with_app_auth_and_ignore_github_token", func(t *testing.T) {
t.Skip("This test requires a valid app auth setup to run.")
config := fmt.Sprintf(`
provider "github" {
owner = "%s"
app_auth {
id = "1234567890"
installation_id = "1234567890"
pem_file = "1234567890"
}
}

data "github_ip_ranges" "test" {}
`, testAccConf.owner)

resource.Test(t, resource.TestCase{
PreCheck: func() { t.Setenv("GITHUB_TOKEN", "1234567890") },
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: config,
ExpectNonEmptyPlan: false,
},
},
})
})

t.Run("can be configured to run insecurely", func(t *testing.T) {
config := `
provider "github" {
token = ""
insecure = true
}
data "github_ip_ranges" "test" {}
Expand Down Expand Up @@ -231,6 +257,7 @@ func TestAccProviderConfigure(t *testing.T) {
})
})
t.Run("should not allow both token and app_auth to be configured", func(t *testing.T) {
t.Skip("This would be a semver breaking change, this will be reinstated for v7.")
config := fmt.Sprintf(`
provider "github" {
owner = "%s"
Expand All @@ -255,29 +282,4 @@ func TestAccProviderConfigure(t *testing.T) {
},
})
})
t.Run("should not allow app_auth and GITHUB_TOKEN to be configured", func(t *testing.T) {
config := fmt.Sprintf(`
provider "github" {
owner = "%s"
app_auth {
id = "1234567890"
installation_id = "1234567890"
pem_file = "1234567890"
}
}

data "github_ip_ranges" "test" {}
`, testAccConf.owner)

resource.Test(t, resource.TestCase{
PreCheck: func() { t.Setenv("GITHUB_TOKEN", "1234567890") },
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: config,
ExpectError: regexp.MustCompile(`"token": conflicts with app_auth`),
},
},
})
})
}