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

Function TestPrMerge_deleteBranch_apiError

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

Source from the content-addressed store, hash-verified

725}
726
727func TestPrMerge_deleteBranch_apiError(t *testing.T) {
728 tests := []struct {
729 name string
730 apiError ghapi.HTTPError
731 wantErr string
732 wantStderr string
733 }{
734 {
735 name: "branch already deleted (422: Reference does not exist)",
736 apiError: ghapi.HTTPError{
737 Message: "Reference does not exist",
738 StatusCode: http.StatusUnprocessableEntity, // 422
739 },
740 wantStderr: heredoc.Doc(`
741 ✓ Merged pull request OWNER/REPO#10 (Blueberries are a good fruit)
742 ✓ Deleted local branch blueberries and switched to branch main
743 ✓ Deleted remote branch blueberries
744 `),
745 },
746 {
747 name: "branch already deleted (404: Reference does not exist) (#11187)",
748 apiError: ghapi.HTTPError{
749 Message: "Reference does not exist",
750 StatusCode: http.StatusNotFound, // 404
751 },
752 wantStderr: heredoc.Doc(`
753 ✓ Merged pull request OWNER/REPO#10 (Blueberries are a good fruit)
754 ✓ Deleted local branch blueberries and switched to branch main
755 ✓ Deleted remote branch blueberries
756 `),
757 },
758 {
759 name: "unknown API error",
760 apiError: ghapi.HTTPError{
761 Message: "blah blah",
762 StatusCode: http.StatusInternalServerError, // 500
763 },
764 wantStderr: heredoc.Doc(`
765 ✓ Merged pull request OWNER/REPO#10 (Blueberries are a good fruit)
766 ✓ Deleted local branch blueberries and switched to branch main
767 `),
768 wantErr: "failed to delete remote branch blueberries: HTTP 500: blah blah (https://api.github.com/repos/OWNER/REPO/git/refs/heads%2Fblueberries)",
769 },
770 }
771
772 for _, tt := range tests {
773 t.Run(tt.name, func(t *testing.T) {
774 http := initFakeHTTP()
775 defer http.Verify(t)
776
777 shared.StubFinderForRunCommandStyleTests(t,
778 "",
779 &api.PullRequest{
780 ID: "PR_10",
781 Number: 10,
782 State: "OPEN",
783 Title: "Blueberries are a good fruit",
784 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