@@ -400,4 +400,69 @@ func TestAccGithubRepositoryFile(t *testing.T) {
400400 },
401401 })
402402 })
403+ t .Run ("imports_files_without_error" , func (t * testing.T ) {
404+ randomID := acctest .RandString (5 )
405+ repoName := fmt .Sprintf ("%sfile-import-%s" , testResourcePrefix , randomID )
406+ config := fmt .Sprintf (`
407+ resource "github_repository" "test" {
408+ name = "%s"
409+ auto_init = true
410+ vulnerability_alerts = true
411+ }
412+
413+ resource "github_repository_file" "test" {
414+ repository = github_repository.test.name
415+ file = "test"
416+ content = "bar"
417+ commit_message = "Managed by Terraform"
418+ commit_author = "Terraform User"
419+ commit_email = "[email protected] " 420+ }
421+ ` , repoName )
422+
423+ resource .Test (t , resource.TestCase {
424+ PreCheck : func () { skipUnauthenticated (t ) },
425+ ProviderFactories : providerFactories ,
426+ Steps : []resource.TestStep {
427+ {
428+ 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+ ),
454+ resource .TestCheckNoResourceAttr ("github_repository_file.test" , "autocreate_branch" ),
455+ resource .TestCheckNoResourceAttr ("github_repository_file.test" , "autocreate_branch_source_branch" ),
456+ resource .TestCheckNoResourceAttr ("github_repository_file.test" , "autocreate_branch_source_sha" ),
457+ ),
458+ },
459+ {
460+ ResourceName : "github_repository_file.test" ,
461+ ImportState : true ,
462+ ImportStateVerify : true ,
463+ ImportStateId : fmt .Sprintf ("%s/%s:main" , repoName , "test" ),
464+ },
465+ },
466+ })
467+ })
403468}
0 commit comments