(t *testing.T)
| 755 | } |
| 756 | |
| 757 | func TestRepoExists(t *testing.T) { |
| 758 | tests := []struct { |
| 759 | name string |
| 760 | httpStub func(*httpmock.Registry) |
| 761 | repo ghrepo.Interface |
| 762 | existCheck bool |
| 763 | wantErrMsg string |
| 764 | }{ |
| 765 | { |
| 766 | name: "repo exists", |
| 767 | httpStub: func(r *httpmock.Registry) { |
| 768 | r.Register( |
| 769 | httpmock.REST("HEAD", "repos/OWNER/REPO"), |
| 770 | httpmock.StringResponse("{}"), |
| 771 | ) |
| 772 | }, |
| 773 | repo: ghrepo.New("OWNER", "REPO"), |
| 774 | existCheck: true, |
| 775 | wantErrMsg: "", |
| 776 | }, |
| 777 | { |
| 778 | name: "repo does not exists", |
| 779 | httpStub: func(r *httpmock.Registry) { |
| 780 | r.Register( |
| 781 | httpmock.REST("HEAD", "repos/OWNER/REPO"), |
| 782 | httpmock.StatusStringResponse(404, "Not Found"), |
| 783 | ) |
| 784 | }, |
| 785 | repo: ghrepo.New("OWNER", "REPO"), |
| 786 | existCheck: false, |
| 787 | wantErrMsg: "", |
| 788 | }, |
| 789 | { |
| 790 | name: "http error", |
| 791 | httpStub: func(r *httpmock.Registry) { |
| 792 | r.Register( |
| 793 | httpmock.REST("HEAD", "repos/OWNER/REPO"), |
| 794 | httpmock.StatusStringResponse(500, "Internal Server Error"), |
| 795 | ) |
| 796 | }, |
| 797 | repo: ghrepo.New("OWNER", "REPO"), |
| 798 | existCheck: false, |
| 799 | wantErrMsg: "HTTP 500 (https://api.github.com/repos/OWNER/REPO)", |
| 800 | }, |
| 801 | } |
| 802 | for _, tt := range tests { |
| 803 | reg := &httpmock.Registry{} |
| 804 | if tt.httpStub != nil { |
| 805 | tt.httpStub(reg) |
| 806 | } |
| 807 | |
| 808 | client := newTestClient(reg) |
| 809 | |
| 810 | t.Run(tt.name, func(t *testing.T) { |
| 811 | exist, err := RepoExists(client, ghrepo.New("OWNER", "REPO")) |
| 812 | if tt.wantErrMsg != "" { |
| 813 | assert.Equal(t, tt.wantErrMsg, err.Error()) |
| 814 | } else { |
nothing calls this directly
no test coverage detected