@@ -2,6 +2,7 @@ package github
22
33import (
44 "fmt"
5+ "regexp"
56 "testing"
67
78 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
@@ -53,7 +54,7 @@ func TestAccProviderConfigure(t *testing.T) {
5354 t .Run ("can be configured to run anonymously" , func (t * testing.T ) {
5455 config := `
5556 provider "github" {
56- token = ""
57+ token = ""
5758 }
5859 data "github_ip_ranges" "test" {}
5960 `
@@ -77,7 +78,7 @@ func TestAccProviderConfigure(t *testing.T) {
7778 insecure = true
7879 }
7980 data "github_ip_ranges" "test" {}
80- `
81+ `
8182
8283 resource .Test (t , resource.TestCase {
8384 ProviderFactories : providerFactories ,
@@ -116,39 +117,42 @@ func TestAccProviderConfigure(t *testing.T) {
116117 config := fmt .Sprintf (`
117118 provider "github" {
118119 token = "%s"
119- owner = "%s"
120- }` , testAccConf .token , testAccConf .owner )
120+ owner = "%[2]s"
121+ }
122+
123+ data "github_organization" "test" {
124+ name = "%[2]s"
125+ }
126+ ` , testAccConf .token , testAccConf .owner )
121127
122128 resource .Test (t , resource.TestCase {
123129 PreCheck : func () { skipUnlessHasOrgs (t ) },
124130 ProviderFactories : providerFactories ,
125131 Steps : []resource.TestStep {
126132 {
127- Config : config ,
128- PlanOnly : true ,
129- ExpectNonEmptyPlan : false ,
133+ Config : config ,
130134 },
131135 },
132136 })
137+ })
133138
134- t .Run ("can be configured with an organization account legacy" , func (t * testing.T ) {
135- config := fmt .Sprintf (`
139+ t .Run ("can be configured with an organization account legacy" , func (t * testing.T ) {
140+ config := fmt .Sprintf (`
136141 provider "github" {
137142 token = "%s"
138143 organization = "%s"
139144 }` , testAccConf .token , testAccConf .owner )
140145
141- resource .Test (t , resource.TestCase {
142- PreCheck : func () { skipUnlessHasOrgs (t ) },
143- ProviderFactories : providerFactories ,
144- Steps : []resource.TestStep {
145- {
146- Config : config ,
147- PlanOnly : true ,
148- ExpectNonEmptyPlan : false ,
149- },
146+ resource .Test (t , resource.TestCase {
147+ PreCheck : func () { skipUnlessHasOrgs (t ) },
148+ ProviderFactories : providerFactories ,
149+ Steps : []resource.TestStep {
150+ {
151+ Config : config ,
152+ PlanOnly : true ,
153+ ExpectNonEmptyPlan : false ,
150154 },
151- })
155+ },
152156 })
153157 })
154158
@@ -172,11 +176,15 @@ func TestAccProviderConfigure(t *testing.T) {
172176 })
173177
174178 t .Run ("can be configured with max retries" , func (t * testing.T ) {
179+ testMaxRetries := - 1
175180 config := fmt .Sprintf (`
176181 provider "github" {
177182 owner = "%s"
178- max_retries = 3
179- }` , testAccConf .owner )
183+ max_retries = %d
184+ }
185+
186+ data "github_ip_ranges" "test" {}
187+ ` , testAccConf .owner , testMaxRetries )
180188
181189 resource .Test (t , resource.TestCase {
182190 PreCheck : func () { skipUnauthenticated (t ) },
@@ -185,17 +193,22 @@ func TestAccProviderConfigure(t *testing.T) {
185193 {
186194 Config : config ,
187195 ExpectNonEmptyPlan : false ,
196+ ExpectError : regexp .MustCompile ("max_retries must be greater than or equal to 0" ),
188197 },
189198 },
190199 })
191200 })
192201
193202 t .Run ("can be configured with max per page" , func (t * testing.T ) {
194- config := `
203+ testMaxPerPage := 101
204+ config := fmt .Sprintf (`
195205 provider "github" {
196206 owner = "%s"
197- max_per_page = 100
198- }`
207+ max_per_page = %d
208+ }
209+
210+ data "github_ip_ranges" "test" {}
211+ ` , testAccConf .owner , testMaxPerPage )
199212
200213 resource .Test (t , resource.TestCase {
201214 PreCheck : func () { skipUnauthenticated (t ) },
@@ -205,13 +218,64 @@ func TestAccProviderConfigure(t *testing.T) {
205218 Config : config ,
206219 ExpectNonEmptyPlan : false ,
207220 Check : func (_ * terraform.State ) error {
208- if maxPerPage != 100 {
209- return fmt .Errorf ("max_per_page should be set to 100 , got %d" , maxPerPage )
221+ if maxPerPage != testMaxPerPage {
222+ return fmt .Errorf ("max_per_page should be set to %d , got %d" , testMaxPerPage , maxPerPage )
210223 }
211224 return nil
212225 },
213226 },
214227 },
215228 })
216229 })
230+ t .Run ("should not allow both token and app_auth to be configured" , func (t * testing.T ) {
231+ config := fmt .Sprintf (`
232+ provider "github" {
233+ owner = "%s"
234+ token = "%s"
235+ app_auth {
236+ id = "1234567890"
237+ installation_id = "1234567890"
238+ pem_file = "1234567890"
239+ }
240+ }
241+
242+ data "github_ip_ranges" "test" {}
243+ ` , testAccConf .owner , testAccConf .token )
244+
245+ resource .Test (t , resource.TestCase {
246+ PreCheck : func () { skipUnauthenticated (t ) },
247+ ProviderFactories : providerFactories ,
248+ Steps : []resource.TestStep {
249+ {
250+ Config : config ,
251+ ExpectError : regexp .MustCompile ("only one of `app_auth,token` can be specified" ),
252+ },
253+ },
254+ })
255+ })
256+ t .Run ("should not allow app_auth and GITHUB_TOKEN to be configured" , func (t * testing.T ) {
257+ config := fmt .Sprintf (`
258+ provider "github" {
259+ owner = "%s"
260+ app_auth {
261+ id = "1234567890"
262+ installation_id = "1234567890"
263+ pem_file = "1234567890"
264+ }
265+ }
266+
267+ data "github_ip_ranges" "test" {}
268+ ` , testAccConf .owner )
269+
270+ resource .Test (t , resource.TestCase {
271+ PreCheck : func () { skipUnauthenticated (t ); t .Setenv ("GITHUB_TOKEN" , "1234567890" ) },
272+ ProviderFactories : providerFactories ,
273+ Steps : []resource.TestStep {
274+ {
275+ Config : config ,
276+ ExpectError : regexp .MustCompile ("only one of `app_auth,token` can be specified" ),
277+ },
278+ },
279+ })
280+ })
217281}
0 commit comments