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

Function TestRepoExists

api/queries_repo_test.go:840–907  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

838}
839
840func 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 {

Callers

nothing calls this directly

Calls 11

RESTFunction · 0.92
StringResponseFunction · 0.92
NewFunction · 0.92
StatusStringResponseFunction · 0.92
newTestClientFunction · 0.85
RepoExistsFunction · 0.85
EqualMethod · 0.80
RunMethod · 0.65
ErrorfMethod · 0.65
RegisterMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected