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

Function TestHasScript

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

Source from the content-addressed store, hash-verified

84}
85
86func TestHasScript(t *testing.T) {
87 repo := ghrepo.New("OWNER", "REPO")
88
89 t.Run("success", func(t *testing.T) {
90 client := extensionHTTPClient(t, "repos/OWNER/REPO/contents/REPO", http.StatusOK, `{"type":"file"}`)
91
92 hasScript, err := hasScript(client, repo)
93
94 require.NoError(t, err)
95 assert.True(t, hasScript)
96 })
97
98 // The contents endpoint returns an array when the requested path is a directory, and
99 // objects with a non-file type for symlinks and submodules. None of these are treated as
100 // a missing script, so they must not surface a decoding error.
101 t.Run("success for non-file content", func(t *testing.T) {
102 for name, body := range map[string]string{
103 "directory listing": `[{"type":"file","name":"REPO"}]`,
104 "directory": `{"type":"dir"}`,
105 "symlink": `{"type":"symlink"}`,
106 "submodule": `{"type":"submodule"}`,
107 } {
108 t.Run(name, func(t *testing.T) {
109 client := extensionHTTPClient(t, "repos/OWNER/REPO/contents/REPO", http.StatusOK, body)
110
111 hasScript, err := hasScript(client, repo)
112
113 require.NoError(t, err)
114 assert.True(t, hasScript)
115 })
116 }
117 })
118
119 t.Run("not found", func(t *testing.T) {
120 client := extensionHTTPClient(t, "repos/OWNER/REPO/contents/REPO", http.StatusNotFound, `{"message":"Not Found"}`)
121
122 hasScript, err := hasScript(client, repo)
123
124 require.NoError(t, err)
125 assert.False(t, hasScript)
126 })
127
128 t.Run("server error", func(t *testing.T) {
129 client := extensionHTTPClient(t, "repos/OWNER/REPO/contents/REPO", http.StatusInternalServerError, `{"message":"Internal Server Error"}`)
130
131 hasScript, err := hasScript(client, repo)
132
133 assert.False(t, hasScript)
134 requireExtensionHTTPError(t, err, http.StatusInternalServerError)
135 })
136}
137
138func TestFetchLatestRelease(t *testing.T) {
139 repo := ghrepo.New("OWNER", "REPO")

Callers

nothing calls this directly

Calls 5

NewFunction · 0.92
extensionHTTPClientFunction · 0.85
hasScriptFunction · 0.85
RunMethod · 0.65

Tested by

no test coverage detected