MCPcopy
hub / github.com/cli/cli / TestRepoExists

Function TestRepoExists

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

Source from the content-addressed store, hash-verified

755}
756
757func 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 {

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