@@ -272,7 +272,7 @@ func TestAccGithubRepositoryFile(t *testing.T) {
272272 t .Run ("creates and manages files on auto created branch if branch does not exist" , func (t * testing.T ) {
273273 randomID := acctest .RandStringFromCharSet (5 , acctest .CharSetAlphaNum )
274274 repoName := fmt .Sprintf ("%srepo-file-%s" , testResourcePrefix , randomID )
275- config := fmt . Sprintf ( `
275+ config := `
276276 resource "github_repository" "test" {
277277 name = "%s"
278278 auto_init = true
@@ -287,53 +287,33 @@ func TestAccGithubRepositoryFile(t *testing.T) {
287287 commit_message = "Managed by Terraform"
288288 commit_author = "Terraform User"
289289 commit_email = "[email protected] " 290- autocreate_branch = false
290+ autocreate_branch = %t
291291 }
292- ` , repoName )
293-
294- check := resource .ComposeTestCheckFunc (
295- resource .TestCheckResourceAttr (
296- "github_repository_file.test" , "content" ,
297- "bar" ,
298- ),
299- resource .TestCheckResourceAttr (
300- "github_repository_file.test" , "sha" ,
301- "ba0e162e1c47469e3fe4b393a8bf8c569f302116" ,
302- ),
303- resource .TestCheckResourceAttr (
304- "github_repository_file.test" , "ref" ,
305- "does/not/exist" ,
306- ),
307- resource .TestCheckResourceAttrSet (
308- "github_repository_file.test" , "commit_author" ,
309- ),
310- resource .TestCheckResourceAttrSet (
311- "github_repository_file.test" , "commit_email" ,
312- ),
313- resource .TestCheckResourceAttrSet (
314- "github_repository_file.test" , "commit_message" ,
315- ),
316- resource .TestCheckResourceAttrSet (
317- "github_repository_file.test" , "commit_sha" ,
318- ),
319- resource .TestCheckResourceAttr ("github_repository_file.test" , "autocreate_branch" , "true" ),
320- resource .TestCheckResourceAttr ("github_repository_file.test" , "autocreate_branch_source_branch" , "main" ),
321- resource .TestCheckResourceAttrSet ("github_repository_file.test" , "autocreate_branch_source_sha" ),
322- )
292+ `
323293
324294 resource .Test (t , resource.TestCase {
325295 PreCheck : func () { skipUnauthenticated (t ) },
326296 ProviderFactories : providerFactories ,
327297 Steps : []resource.TestStep {
328298 {
329- Config : config ,
299+ Config : fmt . Sprintf ( config , repoName , false ) ,
330300 ExpectError : regexp .MustCompile (`unexpected status code: 404 Not Found` ),
331301 },
332302 {
333- Config : strings .Replace (config ,
334- "autocreate_branch = false" ,
335- "autocreate_branch = true" , 1 ),
336- Check : check ,
303+ Config : fmt .Sprintf (config , repoName , true ),
304+ Check : resource .ComposeTestCheckFunc (
305+ resource .TestCheckResourceAttr ("github_repository_file.test" , "content" , "bar" ),
306+ resource .TestCheckResourceAttr ("github_repository_file.test" , "sha" , "ba0e162e1c47469e3fe4b393a8bf8c569f302116" ),
307+ resource .TestCheckResourceAttr ("github_repository_file.test" , "ref" , "does/not/exist" ),
308+ resource .TestCheckResourceAttrSet ("github_repository_file.test" , "commit_author" ),
309+ resource .TestCheckResourceAttrSet ("github_repository_file.test" , "commit_email" ),
310+ resource .TestCheckResourceAttrSet ("github_repository_file.test" , "commit_message" ),
311+ resource .TestCheckResourceAttrSet ("github_repository_file.test" , "commit_sha" ),
312+ resource .TestCheckResourceAttr ("github_repository_file.test" , "autocreate_branch" , "true" ),
313+ resource .TestCheckResourceAttr ("github_repository_file.test" , "autocreate_branch_source_branch" , "main" ),
314+ resource .TestCheckResourceAttrSet ("github_repository_file.test" , "autocreate_branch_source_sha" ),
315+ resource .TestCheckResourceAttrSet ("github_repository_file.test" , "repository_id" ),
316+ ),
337317 },
338318 },
339319 })
@@ -371,19 +351,13 @@ func TestAccGithubRepositoryFile(t *testing.T) {
371351 {
372352 Config : config ,
373353 Check : resource .ComposeTestCheckFunc (
374- resource .TestCheckResourceAttr (
375- "github_repository_file.test" , "file" ,
376- "archived-test.md" ,
377- ),
354+ resource .TestCheckResourceAttr ("github_repository_file.test" , "file" , "archived-test.md" ),
378355 ),
379356 },
380357 {
381358 Config : archivedConfig ,
382359 Check : resource .ComposeTestCheckFunc (
383- resource .TestCheckResourceAttr (
384- "github_repository.test" , "archived" ,
385- "true" ,
386- ),
360+ resource .TestCheckResourceAttr ("github_repository.test" , "archived" , "true" ),
387361 ),
388362 },
389363 // This step should succeed - the file should be removed from state
@@ -426,34 +400,18 @@ func TestAccGithubRepositoryFile(t *testing.T) {
426400 Steps : []resource.TestStep {
427401 {
428402 Config : config ,
429- Check : resource .ComposeTestCheckFunc (
430- resource .TestCheckResourceAttr (
431- "github_repository_file.test" , "content" ,
432- "bar" ,
433- ),
434- resource .TestCheckResourceAttr (
435- "github_repository_file.test" , "sha" ,
436- "ba0e162e1c47469e3fe4b393a8bf8c569f302116" ,
437- ),
438- resource .TestCheckResourceAttr (
439- "github_repository_file.test" , "ref" ,
440- "main" ,
441- ),
442- resource .TestCheckResourceAttrSet (
443- "github_repository_file.test" , "commit_author" ,
444- ),
445- resource .TestCheckResourceAttrSet (
446- "github_repository_file.test" , "commit_email" ,
447- ),
448- resource .TestCheckResourceAttrSet (
449- "github_repository_file.test" , "commit_message" ,
450- ),
451- resource .TestCheckResourceAttrSet (
452- "github_repository_file.test" , "commit_sha" ,
453- ),
403+ Check : resource .ComposeAggregateTestCheckFunc (
404+ resource .TestCheckResourceAttr ("github_repository_file.test" , "content" , "bar" ),
405+ resource .TestCheckResourceAttrSet ("github_repository_file.test" , "sha" ),
406+ resource .TestCheckResourceAttr ("github_repository_file.test" , "ref" , "main" ),
407+ resource .TestCheckResourceAttrSet ("github_repository_file.test" , "commit_author" ),
408+ resource .TestCheckResourceAttrSet ("github_repository_file.test" , "commit_email" ),
409+ resource .TestCheckResourceAttrSet ("github_repository_file.test" , "commit_message" ),
410+ resource .TestCheckResourceAttrSet ("github_repository_file.test" , "commit_sha" ),
454411 resource .TestCheckNoResourceAttr ("github_repository_file.test" , "autocreate_branch" ),
455412 resource .TestCheckNoResourceAttr ("github_repository_file.test" , "autocreate_branch_source_branch" ),
456413 resource .TestCheckNoResourceAttr ("github_repository_file.test" , "autocreate_branch_source_sha" ),
414+ resource .TestCheckResourceAttrSet ("github_repository_file.test" , "repository_id" ),
457415 ),
458416 },
459417 {
@@ -492,34 +450,18 @@ func TestAccGithubRepositoryFile(t *testing.T) {
492450 Steps : []resource.TestStep {
493451 {
494452 Config : config ,
495- Check : resource .ComposeTestCheckFunc (
496- resource .TestCheckResourceAttr (
497- "github_repository_file.test" , "content" ,
498- "bar" ,
499- ),
500- resource .TestCheckResourceAttr (
501- "github_repository_file.test" , "sha" ,
502- "ba0e162e1c47469e3fe4b393a8bf8c569f302116" ,
503- ),
504- resource .TestCheckResourceAttr (
505- "github_repository_file.test" , "ref" ,
506- "main" ,
507- ),
508- resource .TestCheckResourceAttrSet (
509- "github_repository_file.test" , "commit_author" ,
510- ),
511- resource .TestCheckResourceAttrSet (
512- "github_repository_file.test" , "commit_email" ,
513- ),
514- resource .TestCheckResourceAttrSet (
515- "github_repository_file.test" , "commit_message" ,
516- ),
517- resource .TestCheckResourceAttrSet (
518- "github_repository_file.test" , "commit_sha" ,
519- ),
453+ Check : resource .ComposeAggregateTestCheckFunc (
454+ resource .TestCheckResourceAttr ("github_repository_file.test" , "content" , "bar" ),
455+ resource .TestCheckResourceAttrSet ("github_repository_file.test" , "sha" ),
456+ resource .TestCheckResourceAttr ("github_repository_file.test" , "ref" , "main" ),
457+ resource .TestCheckResourceAttrSet ("github_repository_file.test" , "commit_author" ),
458+ resource .TestCheckResourceAttrSet ("github_repository_file.test" , "commit_email" ),
459+ resource .TestCheckResourceAttrSet ("github_repository_file.test" , "commit_message" ),
460+ resource .TestCheckResourceAttrSet ("github_repository_file.test" , "commit_sha" ),
520461 resource .TestCheckNoResourceAttr ("github_repository_file.test" , "autocreate_branch" ),
521462 resource .TestCheckNoResourceAttr ("github_repository_file.test" , "autocreate_branch_source_branch" ),
522463 resource .TestCheckNoResourceAttr ("github_repository_file.test" , "autocreate_branch_source_sha" ),
464+ resource .TestCheckResourceAttrSet ("github_repository_file.test" , "repository_id" ),
523465 ),
524466 },
525467 {
0 commit comments