(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 | for _, tt := range tests { |
| 886 | reg := &httpmock.Registry{} |
| 887 | if tt.httpStub != nil { |
| 888 | tt.httpStub(reg) |
| 889 | } |
| 890 | |
| 891 | client := newTestClient(reg) |
| 892 | |
| 893 | t.Run(tt.name, func(t *testing.T) { |
| 894 | exist, err := RepoExists(client, ghrepo.New("OWNER", "REPO")) |
| 895 | if tt.wantErrMsg != "" { |
| 896 | assert.Equal(t, tt.wantErrMsg, err.Error()) |
| 897 | } else { |
nothing calls this directly
no test coverage detected