Skip to content

Commit 7048a36

Browse files
committed
Add failing regression test for files with colon in name
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
1 parent 7a217c2 commit 7048a36

1 file changed

Lines changed: 46 additions & 0 deletions

File tree

github/resource_github_repository_file_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import (
88

99
"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
1010
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
11+
"github.com/hashicorp/terraform-plugin-testing/knownvalue"
12+
"github.com/hashicorp/terraform-plugin-testing/statecheck"
13+
"github.com/hashicorp/terraform-plugin-testing/tfjsonpath"
1114
)
1215

1316
func TestAccGithubRepositoryFile(t *testing.T) {
@@ -455,4 +458,47 @@ func TestAccGithubRepositoryFile(t *testing.T) {
455458
},
456459
})
457460
})
461+
462+
t.Run("verify_that_id_can_contain_colon_in_file_path", func(t *testing.T) {
463+
randomID := acctest.RandString(5)
464+
repoName := fmt.Sprintf("%srepo-file-%s", testResourcePrefix, randomID)
465+
filePathWithColon := "repro/example:one.yaml"
466+
config := fmt.Sprintf(`
467+
468+
resource "github_repository" "test" {
469+
name = "%s"
470+
auto_init = true
471+
vulnerability_alerts = true
472+
}
473+
474+
resource "github_repository_file" "test" {
475+
repository = github_repository.test.name
476+
branch = "main"
477+
file = "%s"
478+
content = "bar"
479+
commit_message = "Managed by Terraform"
480+
commit_author = "Terraform User"
481+
commit_email = "terraform@example.com"
482+
}
483+
`, repoName, filePathWithColon)
484+
485+
resource.Test(t, resource.TestCase{
486+
PreCheck: func() { skipUnauthenticated(t) },
487+
ProviderFactories: providerFactories,
488+
Steps: []resource.TestStep{
489+
{
490+
Config: config,
491+
ConfigStateChecks: []statecheck.StateCheck{
492+
statecheck.ExpectKnownValue("github_repository_file.test", tfjsonpath.New("id"), knownvalue.StringFunc(func(v string) error {
493+
if strings.Contains(v, escapeIDPart(filePathWithColon)) {
494+
return nil
495+
}
496+
return fmt.Errorf("expected id to contain escaped file path, got: %s", v)
497+
})),
498+
statecheck.ExpectKnownValue("github_repository_file.test", tfjsonpath.New("file"), knownvalue.StringExact(filePathWithColon)),
499+
},
500+
},
501+
},
502+
})
503+
})
458504
}

0 commit comments

Comments
 (0)