(t *testing.T)
| 188 | } |
| 189 | |
| 190 | func TestFetchReleaseFromTag(t *testing.T) { |
| 191 | repo := ghrepo.New("OWNER", "REPO") |
| 192 | |
| 193 | t.Run("success", func(t *testing.T) { |
| 194 | client := extensionHTTPClient(t, "repos/OWNER/REPO/releases/tags/v1.2.3", http.StatusOK, `{"tag_name":"v1.2.3","assets":[{"name":"asset","url":"https://example.com/asset"}]}`) |
| 195 | |
| 196 | got, err := fetchReleaseFromTag(client, repo, "v1.2.3") |
| 197 | |
| 198 | require.NoError(t, err) |
| 199 | assert.Equal(t, &release{ |
| 200 | Tag: "v1.2.3", |
| 201 | Assets: []releaseAsset{{ |
| 202 | Name: "asset", |
| 203 | APIURL: "https://example.com/asset", |
| 204 | }}, |
| 205 | }, got) |
| 206 | }) |
| 207 | |
| 208 | t.Run("not found", func(t *testing.T) { |
| 209 | client := extensionHTTPClient(t, "repos/OWNER/REPO/releases/tags/v1.2.3", http.StatusNotFound, `{"message":"Not Found"}`) |
| 210 | |
| 211 | got, err := fetchReleaseFromTag(client, repo, "v1.2.3") |
| 212 | |
| 213 | assert.Nil(t, got) |
| 214 | require.Same(t, releaseNotFoundErr, err) |
| 215 | }) |
| 216 | |
| 217 | t.Run("server error", func(t *testing.T) { |
| 218 | client := extensionHTTPClient(t, "repos/OWNER/REPO/releases/tags/v1.2.3", http.StatusInternalServerError, `{"message":"Internal Server Error"}`) |
| 219 | |
| 220 | got, err := fetchReleaseFromTag(client, repo, "v1.2.3") |
| 221 | |
| 222 | assert.Nil(t, got) |
| 223 | requireExtensionHTTPError(t, err, http.StatusInternalServerError) |
| 224 | }) |
| 225 | |
| 226 | for _, status := range []int{http.StatusNoContent, http.StatusResetContent} { |
| 227 | t.Run(http.StatusText(status), func(t *testing.T) { |
| 228 | client := extensionHTTPClient(t, "repos/OWNER/REPO/releases/tags/v1.2.3", status, "") |
| 229 | |
| 230 | got, err := fetchReleaseFromTag(client, repo, "v1.2.3") |
| 231 | |
| 232 | assert.Nil(t, got) |
| 233 | require.EqualError(t, err, "unexpected end of JSON input") |
| 234 | }) |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | // TestFetchCommitSHA covers the two things that kept this site on the raw client: the custom |
| 239 | // Accept media type that makes the API answer with a bare SHA, and the 422 sentinel. |
nothing calls this directly
no test coverage detected