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

Function TestFetchLatestRelease

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

Source from the content-addressed store, hash-verified

140}
141
142func TestFetchLatestRelease(t *testing.T) {
143 repo := ghrepo.New("OWNER", "REPO")
144
145 t.Run("success", func(t *testing.T) {
146 client := extensionHTTPClient(t, "repos/OWNER/REPO/releases/latest", http.StatusOK, `{"tag_name":"v1.2.3","assets":[{"name":"asset","url":"https://example.com/asset"}]}`)
147
148 got, err := fetchLatestRelease(client, repo)
149
150 require.NoError(t, err)
151 assert.Equal(t, &release{
152 Tag: "v1.2.3",
153 Assets: []releaseAsset{{
154 Name: "asset",
155 APIURL: "https://example.com/asset",
156 }},
157 }, got)
158 })
159
160 t.Run("not found", func(t *testing.T) {
161 client := extensionHTTPClient(t, "repos/OWNER/REPO/releases/latest", http.StatusNotFound, `{"message":"Not Found"}`)
162
163 got, err := fetchLatestRelease(client, repo)
164
165 assert.Nil(t, got)
166 require.Same(t, releaseNotFoundErr, err)
167 })
168
169 t.Run("server error", func(t *testing.T) {
170 client := extensionHTTPClient(t, "repos/OWNER/REPO/releases/latest", http.StatusInternalServerError, `{"message":"Internal Server Error"}`)
171
172 got, err := fetchLatestRelease(client, repo)
173
174 assert.Nil(t, got)
175 requireExtensionHTTPError(t, err, http.StatusInternalServerError)
176 })
177
178 for _, status := range []int{http.StatusNoContent, http.StatusResetContent} {
179 t.Run(http.StatusText(status), func(t *testing.T) {
180 client := extensionHTTPClient(t, "repos/OWNER/REPO/releases/latest", status, "")
181
182 got, err := fetchLatestRelease(client, repo)
183
184 assert.Nil(t, got)
185 require.EqualError(t, err, "unexpected end of JSON input")
186 })
187 }
188}
189
190func TestFetchReleaseFromTag(t *testing.T) {
191 repo := ghrepo.New("OWNER", "REPO")

Callers

nothing calls this directly

Calls 6

NewFunction · 0.92
extensionHTTPClientFunction · 0.85
fetchLatestReleaseFunction · 0.85
EqualMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected