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