|
4 | 4 | "fmt" |
5 | 5 | "testing" |
6 | 6 |
|
| 7 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" |
7 | 8 | "github.com/hashicorp/terraform-plugin-testing/compare" |
8 | 9 | "github.com/hashicorp/terraform-plugin-testing/helper/acctest" |
9 | 10 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" |
@@ -475,3 +476,43 @@ func TestAccGithubBranchDefault(t *testing.T) { |
475 | 476 | }) |
476 | 477 | }) |
477 | 478 | } |
| 479 | + |
| 480 | +func TestGithubBranchDefault(t *testing.T) { |
| 481 | + // Test verifies that waitForDefaultBranch |
| 482 | + // is not called when wait_for_rename is false (the default). The mock server |
| 483 | + // is set up with exactly two responses: the initial GET and the rename POST. |
| 484 | + // Any additional request (i.e. a polling GET from waitForDefaultBranch) would |
| 485 | + // receive a 400 from the mock, causing the resource function to return an error. |
| 486 | + t.Run("skips_wait_for_rename_when_not_configured", func(t *testing.T) { |
| 487 | + ts := githubApiMock([]*mockResponse{ |
| 488 | + { |
| 489 | + ExpectedUri: "/repos/owner/repo", |
| 490 | + ExpectedMethod: "GET", |
| 491 | + StatusCode: 200, |
| 492 | + ResponseBody: `{"id": 42, "name": "repo", "default_branch": "main"}`, |
| 493 | + }, |
| 494 | + { |
| 495 | + ExpectedUri: "/repos/owner/repo/branches/main/rename", |
| 496 | + ExpectedMethod: "POST", |
| 497 | + StatusCode: 201, |
| 498 | + ResponseBody: `{"name": "development"}`, |
| 499 | + }, |
| 500 | + }) |
| 501 | + defer ts.Close() |
| 502 | + |
| 503 | + client := mustCreateTestGitHubClient(t, ts.URL) |
| 504 | + meta := &Owner{name: "owner", v3client: client} |
| 505 | + |
| 506 | + d := schema.TestResourceDataRaw(t, resourceGithubBranchDefault().Schema, map[string]any{ |
| 507 | + "repository": "repo", |
| 508 | + "branch": "development", |
| 509 | + "rename": true, |
| 510 | + "wait_for_rename": false, |
| 511 | + }) |
| 512 | + |
| 513 | + diags := resourceGithubBranchDefaultCreate(t.Context(), d, meta) |
| 514 | + if diags.HasError() { |
| 515 | + t.Fatalf("expected no error, got: %v", diags) |
| 516 | + } |
| 517 | + }) |
| 518 | +} |
0 commit comments