From 989152e64ff396ceec1402b7f386f40a035b1e4c Mon Sep 17 00:00:00 2001 From: "Babak K. Shandiz" Date: Tue, 16 Jul 2024 17:33:59 +0100 Subject: [PATCH] Add test case for merge conflict error Signed-off-by: Babak K. Shandiz --- pkg/cmd/pr/update/update_test.go | 44 ++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/pkg/cmd/pr/update/update_test.go b/pkg/cmd/pr/update/update_test.go index 546ca0ed2..2b7bb0682 100644 --- a/pkg/cmd/pr/update/update_test.go +++ b/pkg/cmd/pr/update/update_test.go @@ -315,6 +315,50 @@ func Test_updateRun(t *testing.T) { }, wantsErr: "GraphQL: some error", }, + { + name: "failure, merge conflict error on update request", + input: &UpdateOptions{ + SelectorArg: "123", + }, + httpStubs: func(t *testing.T, reg *httpmock.Registry) { + reg.Register( + httpmock.GraphQL(`query ComparePullRequestBaseBranchWith\b`), + httpmock.GraphQLQuery(`{ + "data": { + "repository": { + "pullRequest": { + "baseRef": { + "compare": { + "aheadBy": 999, + "behindBy": 999, + "Status": "BEHIND" + } + } + } + } + } + }`, func(_ string, inputs map[string]interface{}) { + assert.Equal(t, float64(123), inputs["pullRequestNumber"]) + assert.Equal(t, "head-repository-owner:head-ref-name", inputs["headRef"]) + })) + reg.Register( + httpmock.GraphQL(`mutation PullRequestUpdateBranch\b`), + httpmock.GraphQLMutation(`{ + "data": {}, + "errors": [ + { + "message": "merge conflict between base and head (updatePullRequestBranch)" + } + ] + }`, func(inputs map[string]interface{}) { + assert.Equal(t, "123", inputs["pullRequestId"]) + assert.Equal(t, "head-ref-oid", inputs["expectedHeadOid"]) + assert.Equal(t, "MERGE", inputs["updateMethod"]) + })) + }, + stderr: "X Cannot update PR branch due to conflicts\n", + wantsErr: cmdutil.SilentError.Error(), + }, { name: "failure, API error on update request", input: &UpdateOptions{