MCPcopy Create free account
hub / github.com/cli/cli / TestPrMerge_deleteBranch_apiError

Function TestPrMerge_deleteBranch_apiError

pkg/cmd/pr/merge/merge_test.go:673–770  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

671}
672
673func TestPrMerge_deleteBranch_apiError(t *testing.T) {
674 tests := []struct {
675 name string
676 apiError ghapi.HTTPError
677 wantErr string
678 wantStderr string
679 }{
680 {
681 name: "branch already deleted (422: Reference does not exist)",
682 apiError: ghapi.HTTPError{
683 Message: "Reference does not exist",
684 StatusCode: http.StatusUnprocessableEntity, // 422
685 },
686 wantStderr: heredoc.Doc(`
687 ✓ Merged pull request OWNER/REPO#10 (Blueberries are a good fruit)
688 ✓ Deleted local branch blueberries and switched to branch main
689 ✓ Deleted remote branch blueberries
690 `),
691 },
692 {
693 name: "branch already deleted (404: Reference does not exist) (#11187)",
694 apiError: ghapi.HTTPError{
695 Message: "Reference does not exist",
696 StatusCode: http.StatusNotFound, // 404
697 },
698 wantStderr: heredoc.Doc(`
699 ✓ Merged pull request OWNER/REPO#10 (Blueberries are a good fruit)
700 ✓ Deleted local branch blueberries and switched to branch main
701 ✓ Deleted remote branch blueberries
702 `),
703 },
704 {
705 name: "unknown API error",
706 apiError: ghapi.HTTPError{
707 Message: "blah blah",
708 StatusCode: http.StatusInternalServerError, // 500
709 },
710 wantStderr: heredoc.Doc(`
711 ✓ Merged pull request OWNER/REPO#10 (Blueberries are a good fruit)
712 ✓ Deleted local branch blueberries and switched to branch main
713 `),
714 wantErr: "failed to delete remote branch blueberries: HTTP 500: blah blah (https://api.github.com/repos/OWNER/REPO/git/refs/heads%2Fblueberries)",
715 },
716 }
717
718 for _, tt := range tests {
719 t.Run(tt.name, func(t *testing.T) {
720 http := initFakeHTTP()
721 defer http.Verify(t)
722
723 shared.StubFinderForRunCommandStyleTests(t,
724 "",
725 &api.PullRequest{
726 ID: "PR_10",
727 Number: 10,
728 State: "OPEN",
729 Title: "Blueberries are a good fruit",
730 HeadRefName: "blueberries",

Callers

nothing calls this directly

Calls 15

GraphQLFunction · 0.92
GraphQLMutationFunction · 0.92
RESTFunction · 0.92
JSONErrorResponseFunction · 0.92
StubFunction · 0.92
baseRepoFunction · 0.85
singleWorktreeFunction · 0.85
EqualMethod · 0.80
StderrMethod · 0.80
initFakeHTTPFunction · 0.70
runCommandFunction · 0.70

Tested by

no test coverage detected