@@ -343,6 +343,72 @@ func TestSPRBasicFlowFourCommits(t *testing.T) {
343343 output .Reset ()
344344}
345345
346+ func TestSPRBasicFlowDeleteBranch (t * testing.T ) {
347+ s , gitmock , githubmock , _ , output := makeTestObjects (t )
348+ s .config .User .DeleteMergedBranches = true
349+ assert := require .New (t )
350+ ctx := context .Background ()
351+
352+ c1 := git.Commit {
353+ CommitID : "00000001" ,
354+ CommitHash : "c100000000000000000000000000000000000000" ,
355+ Subject : "test commit 1" ,
356+ }
357+ c2 := git.Commit {
358+ CommitID : "00000002" ,
359+ CommitHash : "c200000000000000000000000000000000000000" ,
360+ Subject : "test commit 2" ,
361+ }
362+
363+ // 'git spr update' :: UpdatePullRequest :: commits=[c1]
364+ githubmock .ExpectGetInfo ()
365+ gitmock .ExpectFetch ()
366+ gitmock .ExpectLogAndRespond ([]* git.Commit {& c1 })
367+ gitmock .ExpectPushCommits ([]* git.Commit {& c1 })
368+ githubmock .ExpectCreatePullRequest (c1 , nil )
369+ githubmock .ExpectGetAssignableUsers ()
370+ githubmock .ExpectAddReviewers ([]string {mockclient .NobodyUserID })
371+ githubmock .ExpectUpdatePullRequest (c1 , nil )
372+ githubmock .ExpectGetInfo ()
373+ s .UpdatePullRequests (ctx , []string {mockclient .NobodyLogin }, nil )
374+ fmt .Printf ("OUT: %s\n " , output .String ())
375+ assert .Equal ("[vvvv] 1 : test commit 1\n " , output .String ())
376+ output .Reset ()
377+
378+ // 'git spr update' :: UpdatePullRequest :: commits=[c1, c2]
379+ githubmock .ExpectGetInfo ()
380+ gitmock .ExpectFetch ()
381+ gitmock .ExpectLogAndRespond ([]* git.Commit {& c2 , & c1 })
382+ gitmock .ExpectPushCommits ([]* git.Commit {& c2 })
383+ githubmock .ExpectCreatePullRequest (c2 , & c1 )
384+ githubmock .ExpectGetAssignableUsers ()
385+ githubmock .ExpectAddReviewers ([]string {mockclient .NobodyUserID })
386+ githubmock .ExpectUpdatePullRequest (c1 , nil )
387+ githubmock .ExpectUpdatePullRequest (c2 , & c1 )
388+ githubmock .ExpectGetInfo ()
389+ s .UpdatePullRequests (ctx , []string {mockclient .NobodyLogin }, nil )
390+ lines := strings .Split (output .String (), "\n " )
391+ fmt .Printf ("OUT: %s\n " , output .String ())
392+ assert .Equal ("warning: not updating reviewers for PR #1" , lines [0 ])
393+ assert .Equal ("[vvvv] 1 : test commit 2" , lines [1 ])
394+ assert .Equal ("[vvvv] 1 : test commit 1" , lines [2 ])
395+ output .Reset ()
396+
397+ // 'git spr merge' :: MergePullRequest :: commits=[a1, a2]
398+ githubmock .ExpectGetInfo ()
399+ githubmock .ExpectUpdatePullRequest (c2 , nil )
400+ githubmock .ExpectMergePullRequest (c2 , genclient .PullRequestMergeMethod_REBASE )
401+ gitmock .ExpectDeleteBranch ("from_branch" ) // <--- This is the key expectation of this test.
402+ githubmock .ExpectCommentPullRequest (c1 )
403+ githubmock .ExpectClosePullRequest (c1 )
404+ gitmock .ExpectDeleteBranch ("from_branch" ) // <--- This is the key expectation of this test.
405+ s .MergePullRequests (ctx , nil )
406+ lines = strings .Split (output .String (), "\n " )
407+ assert .Equal ("MERGED 1 : test commit 1" , lines [0 ])
408+ fmt .Printf ("OUT: %s\n " , output .String ())
409+ output .Reset ()
410+ }
411+
346412func TestSPRMergeCount (t * testing.T ) {
347413 s , gitmock , githubmock , _ , output := makeTestObjects (t )
348414 assert := require .New (t )
0 commit comments