forked from actions/create-github-app-token
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
resolves actions#71 - Add p-retry library - Extract logic to new functions to improve the usage of retry logic
- Loading branch information
Showing
7 changed files
with
211 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { test } from "./main.js"; | ||
|
||
// Verify `main` retry when the GitHub API returns a 500 error. | ||
await test((mockPool) => { | ||
process.env.INPUT_OWNER = 'actions' | ||
process.env.INPUT_REPOSITORIES = 'failed-repo'; | ||
const owner = process.env.INPUT_OWNER | ||
const repo = process.env.INPUT_REPOSITORIES | ||
const mockInstallationId = "123456"; | ||
|
||
mockPool | ||
.intercept({ | ||
path: `/repos/${owner}/${repo}/installation`, | ||
method: "GET", | ||
headers: { | ||
accept: "application/vnd.github.v3+json", | ||
"user-agent": "actions/create-github-app-token", | ||
// Intentionally omitting the `authorization` header, since JWT creation is not idempotent. | ||
}, | ||
}) | ||
.reply(500, 'GitHub API not available') | ||
|
||
mockPool | ||
.intercept({ | ||
path: `/repos/${owner}/${repo}/installation`, | ||
method: "GET", | ||
headers: { | ||
accept: "application/vnd.github.v3+json", | ||
"user-agent": "actions/create-github-app-token", | ||
// Intentionally omitting the `authorization` header, since JWT creation is not idempotent. | ||
}, | ||
}) | ||
.reply( | ||
200, | ||
{ id: mockInstallationId }, | ||
{ headers: { "content-type": "application/json" } } | ||
); | ||
|
||
}); |
36 changes: 36 additions & 0 deletions
36
tests/main-token-get-owner-set-to-user-fail-response.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { test } from "./main.js"; | ||
|
||
// Verify `main` successfully obtains a token when the `owner` input is set (to a user), but the `repositories` input isn’t set. | ||
await test((mockPool) => { | ||
process.env.INPUT_OWNER = "smockle"; | ||
delete process.env.INPUT_REPOSITORIES; | ||
|
||
// Mock installation id request | ||
const mockInstallationId = "123456"; | ||
mockPool | ||
.intercept({ | ||
path: `/orgs/${process.env.INPUT_OWNER}/installation`, | ||
method: "GET", | ||
headers: { | ||
accept: "application/vnd.github.v3+json", | ||
"user-agent": "actions/create-github-app-token", | ||
// Intentionally omitting the `authorization` header, since JWT creation is not idempotent. | ||
}, | ||
}) | ||
.reply(500, 'GitHub API not available') | ||
mockPool | ||
.intercept({ | ||
path: `/orgs/${process.env.INPUT_OWNER}/installation`, | ||
method: "GET", | ||
headers: { | ||
accept: "application/vnd.github.v3+json", | ||
"user-agent": "actions/create-github-app-token", | ||
// Intentionally omitting the `authorization` header, since JWT creation is not idempotent. | ||
}, | ||
}) | ||
.reply( | ||
200, | ||
{ id: mockInstallationId }, | ||
{ headers: { "content-type": "application/json" } } | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.