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

Function TestRepoExists

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

Source from the content-addressed store, hash-verified

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

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