| 279 | } |
| 280 | |
| 281 | func StubFetchRelease(t *testing.T, reg *httpmock.Registry, owner, repoName, tagName, responseBody string) { |
| 282 | path := "repos/OWNER/REPO/releases/tags/v1.2.3" |
| 283 | if tagName == "" { |
| 284 | path = "repos/OWNER/REPO/releases/latest" |
| 285 | } |
| 286 | |
| 287 | reg.Register(httpmock.REST("GET", path), httpmock.StringResponse(responseBody)) |
| 288 | |
| 289 | if tagName != "" { |
| 290 | reg.Register( |
| 291 | httpmock.GraphQL(`query RepositoryReleaseByTag\b`), |
| 292 | httpmock.GraphQLQuery(`{ "data": { "repository": { "release": null }}}`, |
| 293 | func(q string, vars map[string]interface{}) { |
| 294 | assert.Equal(t, owner, vars["owner"]) |
| 295 | assert.Equal(t, repoName, vars["name"]) |
| 296 | assert.Equal(t, tagName, vars["tagName"]) |
| 297 | }), |
| 298 | ) |
| 299 | } |
| 300 | } |
| 301 | |
| 302 | func StubFetchRefSHA(t *testing.T, reg *httpmock.Registry, owner, repoName, tagName, sha string) { |
| 303 | path := fmt.Sprintf("repos/%s/%s/git/ref/tags/%s", owner, repoName, tagName) |