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

Function TestRepoExists

pkg/cmd/extension/http_test.go:38–84  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

36}
37
38func TestRepoExists(t *testing.T) {
39 repo := ghrepo.New("OWNER", "REPO")
40
41 for name, body := range map[string]string{
42 "JSON body": `{}`,
43 "empty body": "",
44 "non-JSON body": "repository",
45 } {
46 t.Run("success with "+name, func(t *testing.T) {
47 client := extensionHTTPClient(t, "repos/OWNER/REPO", http.StatusOK, body)
48
49 exists, err := repoExists(client, repo)
50
51 require.NoError(t, err)
52 assert.True(t, exists)
53 })
54 }
55
56 t.Run("not found", func(t *testing.T) {
57 client := extensionHTTPClient(t, "repos/OWNER/REPO", http.StatusNotFound, `{"message":"Not Found"}`)
58
59 exists, err := repoExists(client, repo)
60
61 require.NoError(t, err)
62 assert.False(t, exists)
63 })
64
65 t.Run("server error", func(t *testing.T) {
66 client := extensionHTTPClient(t, "repos/OWNER/REPO", http.StatusInternalServerError, `{"message":"Internal Server Error"}`)
67
68 exists, err := repoExists(client, repo)
69
70 assert.False(t, exists)
71 requireExtensionHTTPError(t, err, http.StatusInternalServerError)
72 })
73
74 for _, status := range []int{http.StatusCreated, http.StatusNoContent} {
75 t.Run("unexpected "+http.StatusText(status), func(t *testing.T) {
76 client := extensionHTTPClient(t, "repos/OWNER/REPO", status, `{"message":"Unexpected status"}`)
77
78 exists, err := repoExists(client, repo)
79
80 assert.False(t, exists)
81 requireExtensionHTTPError(t, err, status)
82 })
83 }
84}
85
86func TestHasScript(t *testing.T) {
87 repo := ghrepo.New("OWNER", "REPO")

Callers

nothing calls this directly

Calls 5

NewFunction · 0.92
extensionHTTPClientFunction · 0.85
repoExistsFunction · 0.85
RunMethod · 0.65

Tested by

no test coverage detected