diff options
| author | Mike Vink <mike1994vink@gmail.com> | 2023-02-27 12:32:30 +0100 |
|---|---|---|
| committer | Mike Vink <mike1994vink@gmail.com> | 2023-02-28 10:14:28 +0100 |
| commit | c08b40bf9d9bb8b5f78169986c35a460a81654e1 (patch) | |
| tree | 2cb6f6fef6aa2360eaef302989ed85cd60fadb16 | |
| parent | 27d80129ec8d959ec375873090bb2eec825ec671 (diff) | |
fix: Incorporate rename requests
3 files changed, 46 insertions, 43 deletions
diff --git a/azuredevops/internal/acceptancetests/resource_git_repository_branch_test.go b/azuredevops/internal/acceptancetests/resource_git_repository_branch_test.go index 2e34eca0..a3a797e6 100644 --- a/azuredevops/internal/acceptancetests/resource_git_repository_branch_test.go +++ b/azuredevops/internal/acceptancetests/resource_git_repository_branch_test.go @@ -30,14 +30,14 @@ func TestAccGitRepoBranch_CreateAndUpdate(t *testing.T) { Check: resource.ComposeTestCheckFunc( // test-branch resource.TestCheckResourceAttr("azuredevops_git_repository_branch.from_master", "name", fmt.Sprintf("testbranch-%s", branchName)), - resource.TestCheckResourceAttr("azuredevops_git_repository_branch.from_master", "ref", "master"), + resource.TestCheckResourceAttr("azuredevops_git_repository_branch.from_master", "ref_branch", "master"), resource.TestCheckResourceAttr("azuredevops_git_repository_branch.from_master", "branch_reference", fmt.Sprintf("refs/heads/testbranch-%s", branchName)), - resource.TestCheckResourceAttrSet("azuredevops_git_repository_branch.from_master", "branch_head"), + resource.TestCheckResourceAttrSet("azuredevops_git_repository_branch.from_master", "last_commit_id"), // test-branch2 resource.TestCheckResourceAttr("azuredevops_git_repository_branch.from_commit_id", "name", fmt.Sprintf("testbranch2-%s", branchName)), - resource.TestCheckResourceAttrSet("azuredevops_git_repository_branch.from_commit_id", "commit_id"), + resource.TestCheckResourceAttrSet("azuredevops_git_repository_branch.from_commit_id", "ref_commit_id"), resource.TestCheckResourceAttr("azuredevops_git_repository_branch.from_commit_id", "branch_reference", fmt.Sprintf("refs/heads/testbranch2-%s", branchName)), - resource.TestCheckResourceAttrSet("azuredevops_git_repository_branch.from_commit_id", "branch_head"), + resource.TestCheckResourceAttrSet("azuredevops_git_repository_branch.from_commit_id", "last_commit_id"), ), }, // Test import branch created from ref, ignore fields set only on create @@ -45,7 +45,7 @@ func TestAccGitRepoBranch_CreateAndUpdate(t *testing.T) { ResourceName: "azuredevops_git_repository_branch.from_master", ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"ref", "tag", "commit_id"}, + ImportStateVerifyIgnore: []string{"ref_branch", "ref_tag", "ref_commit_id"}, }, // Test replace/update branch when name changes { @@ -53,14 +53,14 @@ func TestAccGitRepoBranch_CreateAndUpdate(t *testing.T) { Check: resource.ComposeTestCheckFunc( // test-branch resource.TestCheckResourceAttr("azuredevops_git_repository_branch.from_master", "name", fmt.Sprintf("testbranch-%s", branchNameChanged)), - resource.TestCheckResourceAttr("azuredevops_git_repository_branch.from_master", "ref", "master"), + resource.TestCheckResourceAttr("azuredevops_git_repository_branch.from_master", "ref_branch", "master"), resource.TestCheckResourceAttr("azuredevops_git_repository_branch.from_master", "branch_reference", fmt.Sprintf("refs/heads/testbranch-%s", branchNameChanged)), - resource.TestCheckResourceAttrSet("azuredevops_git_repository_branch.from_master", "branch_head"), + resource.TestCheckResourceAttrSet("azuredevops_git_repository_branch.from_master", "last_commit_id"), // test-branch2 resource.TestCheckResourceAttr("azuredevops_git_repository_branch.from_commit_id", "name", fmt.Sprintf("testbranch2-%s", branchNameChanged)), - resource.TestCheckResourceAttrSet("azuredevops_git_repository_branch.from_commit_id", "commit_id"), + resource.TestCheckResourceAttrSet("azuredevops_git_repository_branch.from_commit_id", "ref_commit_id"), resource.TestCheckResourceAttr("azuredevops_git_repository_branch.from_commit_id", "branch_reference", fmt.Sprintf("refs/heads/testbranch2-%s", branchNameChanged)), - resource.TestCheckResourceAttrSet("azuredevops_git_repository_branch.from_commit_id", "branch_head"), + resource.TestCheckResourceAttrSet("azuredevops_git_repository_branch.from_commit_id", "last_commit_id"), ), }, // Test invalid ref @@ -71,7 +71,7 @@ func TestAccGitRepoBranch_CreateAndUpdate(t *testing.T) { resource "azuredevops_git_repository_branch" "from_nonexistent_tag" { repository_id = azuredevops_git_repository.repository.id name = "testbranch-non-existent-tag" - tag = "0.0.0" + ref_tag = "0.0.0" } `, hclGitRepoBranches(projectName, gitRepoName, "Clean", branchNameChanged)), ExpectError: regexp.MustCompile(`No refs found that match ref "refs/tags/0.0.0"`), @@ -89,12 +89,12 @@ func hclGitRepoBranches(projectName, gitRepoName, initType, branchName string) s resource "azuredevops_git_repository_branch" "from_master" { repository_id = azuredevops_git_repository.repository.id name = "testbranch-%[2]s" - ref = "master" + ref_branch = "master" } resource "azuredevops_git_repository_branch" "from_commit_id" { repository_id = azuredevops_git_repository.repository.id name = "testbranch2-%[2]s" - commit_id = azuredevops_git_repository_branch.from_master.branch_head + ref_commit_id = azuredevops_git_repository_branch.from_master.last_commit_id } `, gitRepoResource, branchName) } diff --git a/azuredevops/internal/service/git/resource_git_repository_branch.go b/azuredevops/internal/service/git/resource_git_repository_branch.go index 362694d9..c64a15cf 100644 --- a/azuredevops/internal/service/git/resource_git_repository_branch.go +++ b/azuredevops/internal/service/git/resource_git_repository_branch.go @@ -37,30 +37,33 @@ func ResourceGitRepositoryBranch() *schema.Resource { ForceNew: true, ValidateFunc: validation.IsUUID, }, - "ref": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, - ValidateFunc: validation.StringIsNotEmpty, + "ref_branch": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + ValidateFunc: validation.StringIsNotEmpty, + ConflictsWith: []string{"ref_tag", "ref_commit_id"}, }, - "tag": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, - ValidateFunc: validation.StringIsNotEmpty, + "ref_tag": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + ValidateFunc: validation.StringIsNotEmpty, + ConflictsWith: []string{"ref_branch", "ref_commit_id"}, }, - "commit_id": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, - Computed: true, - ValidateFunc: validation.StringIsNotEmpty, + "ref_commit_id": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + Computed: true, + ValidateFunc: validation.StringIsNotEmpty, + ConflictsWith: []string{"ref_branch", "ref_tag"}, }, "branch_reference": { Type: schema.TypeString, Computed: true, }, - "branch_head": { + "last_commit_id": { Type: schema.TypeString, Computed: true, }, @@ -73,9 +76,9 @@ func resourceGitRepositoryBranchCreate(ctx context.Context, d *schema.ResourceDa repoId := d.Get("repository_id").(string) branchName := d.Get("name").(string) branchRefHeadName := withPrefix("refs/heads/", branchName) - ref, hasRef := d.GetOk("ref") - tag, hasTag := d.GetOk("tag") - _, hasCommitId := d.GetOk("commit_id") + ref, hasRef := d.GetOk("ref_branch") + tag, hasTag := d.GetOk("ref_tag") + _, hasCommitId := d.GetOk("ref_commit_id") if !hasRef && !hasTag && !hasCommitId { return diag.Errorf("One of 'ref' or 'tag' or 'commit_id' must be provided.") @@ -127,9 +130,9 @@ func resourceGitRepositoryBranchCreate(ctx context.Context, d *schema.ResourceDa } else { return diag.FromErr(fmt.Errorf("GetRefs response doesn't have a valid commit id.")) } - d.Set("commit_id", *refObjectIdSha) + d.Set("ref_commit_id", *refObjectIdSha) } - newObjectId := d.Get("commit_id").(string) + newObjectId := d.Get("ref_commit_id").(string) _, err := updateRefs(clients, git.UpdateRefsArgs{ RefUpdates: &[]git.GitRefUpdate{{ @@ -172,7 +175,7 @@ func resourceGitRepositoryBranchRead(ctx context.Context, d *schema.ResourceData d.Set("name", name) d.Set("repository_id", repoId) d.Set("branch_reference", converter.String(withPrefix("refs/heads/", name))) - d.Set("branch_head", *gotBranch.Commit.CommitId) + d.Set("last_commit_id", *gotBranch.Commit.CommitId) return nil } diff --git a/azuredevops/internal/service/git/resource_git_repository_branch_test.go b/azuredevops/internal/service/git/resource_git_repository_branch_test.go index 7a16fd5e..f9ccf548 100644 --- a/azuredevops/internal/service/git/resource_git_repository_branch_test.go +++ b/azuredevops/internal/service/git/resource_git_repository_branch_test.go @@ -39,7 +39,7 @@ func TestGitRepositoryBranch_Create(t *testing.T) { fakeCommitId := "a-commit" branchName := "a-branch" repoId := "a-repo" - d.Set("ref", ref) + d.Set("ref_branch", ref) d.Set("name", branchName) d.Set("repository_id", repoId) @@ -76,19 +76,19 @@ func TestGitRepositoryBranch_Create(t *testing.T) { diag.FromErr(fmt.Errorf("Error creating branch \"a-branch\": an-error")), }, { - "When more than one of commitId, tag, or ref are given, the first one from left to right wins", + "When more than one of ref_commit_id, ref_tag, or ref_branch are given, the first one from left to right wins", func(g *azdosdkmocks.MockGitClient) args { clients := &client.AggregatedClient{ GitReposClient: g, Ctx: context.Background(), } d := schema.TestResourceDataRaw(t, ResourceGitRepositoryBranch().Schema, nil) - tag := "refs/tag/v1.0.0" + tag := "refs/tags/v1.0.0" fakeCommitId := "a-commit" branchName := "a-branch" repoId := "a-repo" - d.Set("commit_id", fakeCommitId) - d.Set("tag", tag) + d.Set("ref_commit_id", fakeCommitId) + d.Set("ref_tag", tag) d.Set("name", branchName) d.Set("repository_id", repoId) @@ -122,7 +122,7 @@ func TestGitRepositoryBranch_Create(t *testing.T) { fakeCommitId := "a-commit" branchName := "a-branch" repoId := "a-repo" - d.Set("ref", ref) + d.Set("ref_branch", ref) d.Set("name", branchName) d.Set("repository_id", repoId) @@ -197,7 +197,7 @@ func TestGitRepositoryBranch_Read(t *testing.T) { } d := schema.TestResourceDataRaw(t, ResourceGitRepositoryBranch().Schema, nil) - d.Set("ref", "another-branch") + d.Set("ref_branch", "another-branch") d.Set("name", "a-branch") d.Set("repository_id", "a-repo") d.SetId("a-repo:a-branch") @@ -253,7 +253,7 @@ func TestGitRepositoryBranch_Delete(t *testing.T) { } d := schema.TestResourceDataRaw(t, ResourceGitRepositoryBranch().Schema, nil) - d.Set("ref", "another-branch") + d.Set("ref_branch", "another-branch") d.Set("name", "a-branch") d.Set("repository_id", "a-repo") d.SetId("a-repo:a-branch") |
