(t *testing.T)
| 838 | } |
| 839 | |
| 840 | func TestRepoExists(t *testing.T) { |
| 841 | tests := []struct { |
| 842 | name string |
| 843 | httpStub func(*httpmock.Registry) |
| 844 | repo ghrepo.Interface |
| 845 | existCheck bool |
| 846 | wantErrMsg string |
| 847 | }{ |
| 848 | { |
| 849 | name: "repo exists", |
| 850 | httpStub: func(r *httpmock.Registry) { |
| 851 | r.Register( |
| 852 | httpmock.REST("HEAD", "repos/OWNER/REPO"), |
| 853 | httpmock.StringResponse("{}"), |
| 854 | ) |
| 855 | }, |
| 856 | repo: ghrepo.New("OWNER", "REPO"), |
| 857 | existCheck: true, |
| 858 | wantErrMsg: "", |
| 859 | }, |
| 860 | { |
| 861 | name: "repo does not exists", |
| 862 | httpStub: func(r *httpmock.Registry) { |
| 863 | r.Register( |
| 864 | httpmock.REST("HEAD", "repos/OWNER/REPO"), |
| 865 | httpmock.StatusStringResponse(404, "Not Found"), |
| 866 | ) |
| 867 | }, |
| 868 | repo: ghrepo.New("OWNER", "REPO"), |
| 869 | existCheck: false, |
| 870 | wantErrMsg: "", |
| 871 | }, |
| 872 | { |
| 873 | name: "http error", |
| 874 | httpStub: func(r *httpmock.Registry) { |
| 875 | r.Register( |
| 876 | httpmock.REST("HEAD", "repos/OWNER/REPO"), |
| 877 | httpmock.StatusStringResponse(500, "Internal Server Error"), |
| 878 | ) |
| 879 | }, |
| 880 | repo: ghrepo.New("OWNER", "REPO"), |
| 881 | existCheck: false, |
| 882 | wantErrMsg: "HTTP 500 (https://api.github.com/repos/OWNER/REPO)", |
| 883 | }, |
| 884 | { |
| 885 | // Only 200 counts as existence. A 2xx other than 200 is unexpected for this |
| 886 | // endpoint and must be reported rather than quietly taken as a yes. |
| 887 | name: "unexpected success status", |
| 888 | httpStub: func(r *httpmock.Registry) { |
| 889 | r.Register( |
| 890 | httpmock.REST("HEAD", "repos/OWNER/REPO"), |
| 891 | httpmock.StatusStringResponse(201, ""), |
| 892 | ) |
| 893 | }, |
| 894 | repo: ghrepo.New("OWNER", "REPO"), |
| 895 | existCheck: false, |
| 896 | wantErrMsg: "unexpected HTTP 201 for HEAD https://api.github.com/repos/OWNER/REPO", |
| 897 | }, |
nothing calls this directly
no test coverage detected