| 306 | } |
| 307 | |
| 308 | func StubFetchRelease(t *testing.T, reg *httpmock.Registry, owner, repoName, tagName, responseBody string) { |
| 309 | path := "repos/OWNER/REPO/releases/tags/v1.2.3" |
| 310 | if tagName == "" { |
| 311 | path = "repos/OWNER/REPO/releases/latest" |
| 312 | } |
| 313 | |
| 314 | reg.Register(httpmock.REST("GET", path), httpmock.StringResponse(responseBody)) |
| 315 | |
| 316 | if tagName != "" { |
| 317 | reg.Register( |
| 318 | httpmock.GraphQL(`query RepositoryReleaseByTag\b`), |
| 319 | httpmock.GraphQLQuery(`{ "data": { "repository": { "release": null }}}`, |
| 320 | func(q string, vars map[string]interface{}) { |
| 321 | assert.Equal(t, owner, vars["owner"]) |
| 322 | assert.Equal(t, repoName, vars["name"]) |
| 323 | assert.Equal(t, tagName, vars["tagName"]) |
| 324 | }), |
| 325 | ) |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | func StubFetchRefSHA(t *testing.T, reg *httpmock.Registry, owner, repoName, tagName, sha string) { |
| 330 | path := fmt.Sprintf("repos/%s/%s/git/ref/tags%%2F%s", owner, repoName, tagName) |