Skip to content

Commit 7b52432

Browse files
committed
Add unit test to verify that waiting is skipped if not configured
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
1 parent c146799 commit 7b52432

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

github/resource_github_branch_default_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"testing"
66

7+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
78
"github.com/hashicorp/terraform-plugin-testing/compare"
89
"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
910
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
@@ -475,3 +476,43 @@ func TestAccGithubBranchDefault(t *testing.T) {
475476
})
476477
})
477478
}
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

Comments
 (0)