|
8 | 8 |
|
9 | 9 | "github.com/hashicorp/terraform-plugin-testing/helper/acctest" |
10 | 10 | "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" |
11 | 14 | ) |
12 | 15 |
|
13 | 16 | func TestAccGithubRepositoryFile(t *testing.T) { |
@@ -455,4 +458,47 @@ func TestAccGithubRepositoryFile(t *testing.T) { |
455 | 458 | }, |
456 | 459 | }) |
457 | 460 | }) |
| 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 | + }) |
458 | 504 | } |
0 commit comments