mirror of
https://github.com/actions/deploy-pages.git
synced 2026-02-09 03:45:15 +00:00
Update tests to use undici mocking for latest Octokit
This commit is contained in:
@@ -1,5 +1,8 @@
|
|||||||
const core = require('@actions/core')
|
const core = require('@actions/core')
|
||||||
|
// For mocking network calls with core http (http-client)
|
||||||
const nock = require('nock')
|
const nock = require('nock')
|
||||||
|
// For mocking network calls with native Fetch (octokit)
|
||||||
|
const { MockAgent, setGlobalDispatcher } = require('undici')
|
||||||
|
|
||||||
const { Deployment, MAX_TIMEOUT, ONE_GIGABYTE, SIZE_LIMIT_DESCRIPTION } = require('../../internal/deployment')
|
const { Deployment, MAX_TIMEOUT, ONE_GIGABYTE, SIZE_LIMIT_DESCRIPTION } = require('../../internal/deployment')
|
||||||
|
|
||||||
@@ -7,6 +10,8 @@ const fakeJwt =
|
|||||||
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJiNjllMWIxOC1jOGFiLTRhZGQtOGYxOC03MzVlMzVjZGJhZjAiLCJzdWIiOiJyZXBvOnBhcGVyLXNwYS9taW55aTplbnZpcm9ubWVudDpQcm9kdWN0aW9uIiwiYXVkIjoiaHR0cHM6Ly9naXRodWIuY29tL3BhcGVyLXNwYSIsInJlZiI6InJlZnMvaGVhZHMvbWFpbiIsInNoYSI6ImEyODU1MWJmODdiZDk3NTFiMzdiMmM0YjM3M2MxZjU3NjFmYWM2MjYiLCJyZXBvc2l0b3J5IjoicGFwZXItc3BhL21pbnlpIiwicmVwb3NpdG9yeV9vd25lciI6InBhcGVyLXNwYSIsInJ1bl9pZCI6IjE1NDY0NTkzNjQiLCJydW5fbnVtYmVyIjoiMzQiLCJydW5fYXR0ZW1wdCI6IjIiLCJhY3RvciI6IllpTXlzdHkiLCJ3b3JrZmxvdyI6IkNJIiwiaGVhZF9yZWYiOiIiLCJiYXNlX3JlZiI6IiIsImV2ZW50X25hbWUiOiJwdXNoIiwicmVmX3R5cGUiOiJicmFuY2giLCJlbnZpcm9ubWVudCI6IlByb2R1Y3Rpb24iLCJqb2Jfd29ya2Zsb3dfcmVmIjoicGFwZXItc3BhL21pbnlpLy5naXRodWIvd29ya2Zsb3dzL2JsYW5rLnltbEByZWZzL2hlYWRzL21haW4iLCJpc3MiOiJodHRwczovL3Rva2VuLmFjdGlvbnMuZ2l0aHVidXNlcmNvbnRlbnQuY29tIiwibmJmIjoxNjM4ODI4MDI4LCJleHAiOjE2Mzg4Mjg5MjgsImlhdCI6MTYzODgyODYyOH0.1wyupfxu1HGoTyIqatYg0hIxy2-0bMO-yVlmLSMuu2w'
|
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJiNjllMWIxOC1jOGFiLTRhZGQtOGYxOC03MzVlMzVjZGJhZjAiLCJzdWIiOiJyZXBvOnBhcGVyLXNwYS9taW55aTplbnZpcm9ubWVudDpQcm9kdWN0aW9uIiwiYXVkIjoiaHR0cHM6Ly9naXRodWIuY29tL3BhcGVyLXNwYSIsInJlZiI6InJlZnMvaGVhZHMvbWFpbiIsInNoYSI6ImEyODU1MWJmODdiZDk3NTFiMzdiMmM0YjM3M2MxZjU3NjFmYWM2MjYiLCJyZXBvc2l0b3J5IjoicGFwZXItc3BhL21pbnlpIiwicmVwb3NpdG9yeV9vd25lciI6InBhcGVyLXNwYSIsInJ1bl9pZCI6IjE1NDY0NTkzNjQiLCJydW5fbnVtYmVyIjoiMzQiLCJydW5fYXR0ZW1wdCI6IjIiLCJhY3RvciI6IllpTXlzdHkiLCJ3b3JrZmxvdyI6IkNJIiwiaGVhZF9yZWYiOiIiLCJiYXNlX3JlZiI6IiIsImV2ZW50X25hbWUiOiJwdXNoIiwicmVmX3R5cGUiOiJicmFuY2giLCJlbnZpcm9ubWVudCI6IlByb2R1Y3Rpb24iLCJqb2Jfd29ya2Zsb3dfcmVmIjoicGFwZXItc3BhL21pbnlpLy5naXRodWIvd29ya2Zsb3dzL2JsYW5rLnltbEByZWZzL2hlYWRzL21haW4iLCJpc3MiOiJodHRwczovL3Rva2VuLmFjdGlvbnMuZ2l0aHVidXNlcmNvbnRlbnQuY29tIiwibmJmIjoxNjM4ODI4MDI4LCJleHAiOjE2Mzg4Mjg5MjgsImlhdCI6MTYzODgyODYyOH0.1wyupfxu1HGoTyIqatYg0hIxy2-0bMO-yVlmLSMuu2w'
|
||||||
|
|
||||||
describe('Deployment', () => {
|
describe('Deployment', () => {
|
||||||
|
let mockPool
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest.clearAllMocks()
|
jest.clearAllMocks()
|
||||||
process.env.ACTIONS_RUNTIME_URL = 'http://my-url/'
|
process.env.ACTIONS_RUNTIME_URL = 'http://my-url/'
|
||||||
@@ -37,11 +42,18 @@ describe('Deployment', () => {
|
|||||||
jest.spyOn(core, 'setFailed').mockImplementation(param => {
|
jest.spyOn(core, 'setFailed').mockImplementation(param => {
|
||||||
return param
|
return param
|
||||||
})
|
})
|
||||||
|
|
||||||
// Mock error/warning/info/debug
|
// Mock error/warning/info/debug
|
||||||
jest.spyOn(core, 'error').mockImplementation(jest.fn())
|
jest.spyOn(core, 'error').mockImplementation(jest.fn())
|
||||||
jest.spyOn(core, 'warning').mockImplementation(jest.fn())
|
jest.spyOn(core, 'warning').mockImplementation(jest.fn())
|
||||||
jest.spyOn(core, 'info').mockImplementation(jest.fn())
|
jest.spyOn(core, 'info').mockImplementation(jest.fn())
|
||||||
jest.spyOn(core, 'debug').mockImplementation(jest.fn())
|
jest.spyOn(core, 'debug').mockImplementation(jest.fn())
|
||||||
|
|
||||||
|
// Set up Fetch mocking
|
||||||
|
const mockAgent = new MockAgent()
|
||||||
|
mockAgent.disableNetConnect()
|
||||||
|
setGlobalDispatcher(mockAgent)
|
||||||
|
mockPool = mockAgent.get('https://api.github.com')
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('#create', () => {
|
describe('#create', () => {
|
||||||
@@ -62,16 +74,32 @@ describe('Deployment', () => {
|
|||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
const createDeploymentScope = nock('https://api.github.com')
|
mockPool
|
||||||
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, {
|
.intercept({
|
||||||
artifact_url: 'https://fake-artifact.com&%24expand=SignedContent',
|
path: `/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`,
|
||||||
pages_build_version: process.env.GITHUB_SHA,
|
method: 'POST',
|
||||||
oidc_token: fakeJwt
|
body: bodyString => {
|
||||||
})
|
const body = JSON.parse(bodyString)
|
||||||
.reply(200, {
|
const keys = Object.keys(body).sort()
|
||||||
status_url: `https://api.github.com/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}`,
|
return (
|
||||||
page_url: 'https://actions.github.io/is-awesome'
|
keys.length === 3 &&
|
||||||
|
keys[0] === 'artifact_url' &&
|
||||||
|
keys[1] === 'oidc_token' &&
|
||||||
|
keys[2] === 'pages_build_version' &&
|
||||||
|
body.artifact_url === 'https://fake-artifact.com&%24expand=SignedContent' &&
|
||||||
|
body.pages_build_version === process.env.GITHUB_SHA &&
|
||||||
|
body.oidc_token === fakeJwt
|
||||||
|
)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
.reply(
|
||||||
|
200,
|
||||||
|
{
|
||||||
|
status_url: `https://api.github.com/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}`,
|
||||||
|
page_url: 'https://actions.github.io/is-awesome'
|
||||||
|
},
|
||||||
|
{ headers: { 'content-type': 'application/json' } }
|
||||||
|
)
|
||||||
|
|
||||||
core.getIDToken = jest.fn().mockResolvedValue(fakeJwt)
|
core.getIDToken = jest.fn().mockResolvedValue(fakeJwt)
|
||||||
|
|
||||||
@@ -85,7 +113,6 @@ describe('Deployment', () => {
|
|||||||
)
|
)
|
||||||
|
|
||||||
artifactExchangeScope.done()
|
artifactExchangeScope.done()
|
||||||
createDeploymentScope.done()
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('can successfully create a preview deployment', async () => {
|
it('can successfully create a preview deployment', async () => {
|
||||||
@@ -100,18 +127,35 @@ describe('Deployment', () => {
|
|||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
const createDeploymentScope = nock('https://api.github.com')
|
mockPool
|
||||||
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, {
|
.intercept({
|
||||||
artifact_url: 'https://fake-artifact.com&%24expand=SignedContent',
|
path: `/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`,
|
||||||
pages_build_version: process.env.GITHUB_SHA,
|
method: 'POST',
|
||||||
oidc_token: fakeJwt,
|
body: bodyString => {
|
||||||
preview: true
|
const body = JSON.parse(bodyString)
|
||||||
})
|
const keys = Object.keys(body).sort()
|
||||||
.reply(200, {
|
return (
|
||||||
status_url: `https://api.github.com/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}`,
|
keys.length === 4 &&
|
||||||
page_url: 'https://actions.github.io/is-awesome',
|
keys[0] === 'artifact_url' &&
|
||||||
preview_url: 'https://actions.drafts.github.io/is-awesome'
|
keys[1] === 'oidc_token' &&
|
||||||
|
keys[2] === 'pages_build_version' &&
|
||||||
|
keys[3] === 'preview' &&
|
||||||
|
body.artifact_url === 'https://fake-artifact.com&%24expand=SignedContent' &&
|
||||||
|
body.pages_build_version === process.env.GITHUB_SHA &&
|
||||||
|
body.oidc_token === fakeJwt &&
|
||||||
|
body.preview === true
|
||||||
|
)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
.reply(
|
||||||
|
200,
|
||||||
|
{
|
||||||
|
status_url: `https://api.github.com/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}`,
|
||||||
|
page_url: 'https://actions.github.io/is-awesome',
|
||||||
|
preview_url: 'https://actions.drafts.github.io/is-awesome'
|
||||||
|
},
|
||||||
|
{ headers: { 'content-type': 'application/json' } }
|
||||||
|
)
|
||||||
|
|
||||||
core.getIDToken = jest.fn().mockResolvedValue(fakeJwt)
|
core.getIDToken = jest.fn().mockResolvedValue(fakeJwt)
|
||||||
|
|
||||||
@@ -128,7 +172,6 @@ describe('Deployment', () => {
|
|||||||
)
|
)
|
||||||
|
|
||||||
artifactExchangeScope.done()
|
artifactExchangeScope.done()
|
||||||
createDeploymentScope.done()
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('reports errors with failed artifact exchange', async () => {
|
it('reports errors with failed artifact exchange', async () => {
|
||||||
@@ -154,12 +197,23 @@ describe('Deployment', () => {
|
|||||||
.get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview')
|
.get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview')
|
||||||
.reply(200, { value: [{ url: 'https://invalid-artifact.com', name: 'github-pages' }] })
|
.reply(200, { value: [{ url: 'https://invalid-artifact.com', name: 'github-pages' }] })
|
||||||
|
|
||||||
const createDeploymentScope = nock('https://api.github.com')
|
mockPool
|
||||||
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, {
|
.intercept({
|
||||||
artifact_url: 'https://invalid-artifact.com&%24expand=SignedContent',
|
path: `/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`,
|
||||||
pages_build_version: process.env.GITHUB_SHA
|
method: 'POST',
|
||||||
|
body: bodyString => {
|
||||||
|
const body = JSON.parse(bodyString)
|
||||||
|
const keys = Object.keys(body).sort()
|
||||||
|
return (
|
||||||
|
keys.length === 2 &&
|
||||||
|
keys[0] === 'artifact_url' &&
|
||||||
|
keys[1] === 'pages_build_version' &&
|
||||||
|
body.artifact_url === 'https://invalid-artifact.com&%24expand=SignedContent' &&
|
||||||
|
body.pages_build_version === process.env.GITHUB_SHA
|
||||||
|
)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.reply(500, { message: 'oh no' })
|
.reply(500, { message: 'oh no' }, { headers: { 'content-type': 'application/json' } })
|
||||||
|
|
||||||
// Create the deployment
|
// Create the deployment
|
||||||
const deployment = new Deployment()
|
const deployment = new Deployment()
|
||||||
@@ -170,7 +224,6 @@ describe('Deployment', () => {
|
|||||||
)
|
)
|
||||||
|
|
||||||
artifactExchangeScope.done()
|
artifactExchangeScope.done()
|
||||||
createDeploymentScope.done()
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('reports errors with an unexpected 403 during deployment', async () => {
|
it('reports errors with an unexpected 403 during deployment', async () => {
|
||||||
@@ -179,12 +232,23 @@ describe('Deployment', () => {
|
|||||||
.get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview')
|
.get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview')
|
||||||
.reply(200, { value: [{ url: 'https://invalid-artifact.com', name: 'github-pages' }] })
|
.reply(200, { value: [{ url: 'https://invalid-artifact.com', name: 'github-pages' }] })
|
||||||
|
|
||||||
const createDeploymentScope = nock('https://api.github.com')
|
mockPool
|
||||||
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, {
|
.intercept({
|
||||||
artifact_url: 'https://invalid-artifact.com&%24expand=SignedContent',
|
path: `/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`,
|
||||||
pages_build_version: process.env.GITHUB_SHA
|
method: 'POST',
|
||||||
|
body: bodyString => {
|
||||||
|
const body = JSON.parse(bodyString)
|
||||||
|
const keys = Object.keys(body).sort()
|
||||||
|
return (
|
||||||
|
keys.length === 2 &&
|
||||||
|
keys[0] === 'artifact_url' &&
|
||||||
|
keys[1] === 'pages_build_version' &&
|
||||||
|
body.artifact_url === 'https://invalid-artifact.com&%24expand=SignedContent' &&
|
||||||
|
body.pages_build_version === process.env.GITHUB_SHA
|
||||||
|
)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.reply(403, { message: 'You are forbidden' })
|
.reply(403, { message: 'You are forbidden' }, { headers: { 'content-type': 'application/json' } })
|
||||||
|
|
||||||
// Create the deployment
|
// Create the deployment
|
||||||
const deployment = new Deployment()
|
const deployment = new Deployment()
|
||||||
@@ -195,7 +259,6 @@ describe('Deployment', () => {
|
|||||||
)
|
)
|
||||||
|
|
||||||
artifactExchangeScope.done()
|
artifactExchangeScope.done()
|
||||||
createDeploymentScope.done()
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('reports errors with an unexpected 404 during deployment', async () => {
|
it('reports errors with an unexpected 404 during deployment', async () => {
|
||||||
@@ -204,12 +267,23 @@ describe('Deployment', () => {
|
|||||||
.get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview')
|
.get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview')
|
||||||
.reply(200, { value: [{ url: 'https://invalid-artifact.com', name: 'github-pages' }] })
|
.reply(200, { value: [{ url: 'https://invalid-artifact.com', name: 'github-pages' }] })
|
||||||
|
|
||||||
const createDeploymentScope = nock('https://api.github.com')
|
mockPool
|
||||||
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, {
|
.intercept({
|
||||||
artifact_url: 'https://invalid-artifact.com&%24expand=SignedContent',
|
path: `/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`,
|
||||||
pages_build_version: process.env.GITHUB_SHA
|
method: 'POST',
|
||||||
|
body: bodyString => {
|
||||||
|
const body = JSON.parse(bodyString)
|
||||||
|
const keys = Object.keys(body).sort()
|
||||||
|
return (
|
||||||
|
keys.length === 2 &&
|
||||||
|
keys[0] === 'artifact_url' &&
|
||||||
|
keys[1] === 'pages_build_version' &&
|
||||||
|
body.artifact_url === 'https://invalid-artifact.com&%24expand=SignedContent' &&
|
||||||
|
body.pages_build_version === process.env.GITHUB_SHA
|
||||||
|
)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.reply(404, { message: 'Not found' })
|
.reply(404, { message: 'Not found' }, { headers: { 'content-type': 'application/json' } })
|
||||||
|
|
||||||
// Create the deployment
|
// Create the deployment
|
||||||
const deployment = new Deployment()
|
const deployment = new Deployment()
|
||||||
@@ -220,7 +294,6 @@ describe('Deployment', () => {
|
|||||||
)
|
)
|
||||||
|
|
||||||
artifactExchangeScope.done()
|
artifactExchangeScope.done()
|
||||||
createDeploymentScope.done()
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('reports errors with failed deployments', async () => {
|
it('reports errors with failed deployments', async () => {
|
||||||
@@ -229,12 +302,23 @@ describe('Deployment', () => {
|
|||||||
.get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview')
|
.get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview')
|
||||||
.reply(200, { value: [{ url: 'https://invalid-artifact.com', name: 'github-pages' }] })
|
.reply(200, { value: [{ url: 'https://invalid-artifact.com', name: 'github-pages' }] })
|
||||||
|
|
||||||
const createDeploymentScope = nock('https://api.github.com')
|
mockPool
|
||||||
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, {
|
.intercept({
|
||||||
artifact_url: 'https://invalid-artifact.com&%24expand=SignedContent',
|
path: `/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`,
|
||||||
pages_build_version: process.env.GITHUB_SHA
|
method: 'POST',
|
||||||
|
body: bodyString => {
|
||||||
|
const body = JSON.parse(bodyString)
|
||||||
|
const keys = Object.keys(body).sort()
|
||||||
|
return (
|
||||||
|
keys.length === 2 &&
|
||||||
|
keys[0] === 'artifact_url' &&
|
||||||
|
keys[1] === 'pages_build_version' &&
|
||||||
|
body.artifact_url === 'https://invalid-artifact.com&%24expand=SignedContent' &&
|
||||||
|
body.pages_build_version === process.env.GITHUB_SHA
|
||||||
|
)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.reply(400, { message: 'Bad request' })
|
.reply(400, { message: 'Bad request' }, { headers: { 'content-type': 'application/json' } })
|
||||||
|
|
||||||
// Create the deployment
|
// Create the deployment
|
||||||
const deployment = new Deployment()
|
const deployment = new Deployment()
|
||||||
@@ -245,7 +329,6 @@ describe('Deployment', () => {
|
|||||||
)
|
)
|
||||||
|
|
||||||
artifactExchangeScope.done()
|
artifactExchangeScope.done()
|
||||||
createDeploymentScope.done()
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('warns if the artifact size is bigger than maximum', async () => {
|
it('warns if the artifact size is bigger than maximum', async () => {
|
||||||
@@ -261,16 +344,32 @@ describe('Deployment', () => {
|
|||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
const createDeploymentScope = nock('https://api.github.com')
|
mockPool
|
||||||
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, {
|
.intercept({
|
||||||
artifact_url: 'https://fake-artifact.com&%24expand=SignedContent',
|
path: `/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`,
|
||||||
pages_build_version: process.env.GITHUB_SHA,
|
method: 'POST',
|
||||||
oidc_token: fakeJwt
|
body: bodyString => {
|
||||||
})
|
const body = JSON.parse(bodyString)
|
||||||
.reply(200, {
|
const keys = Object.keys(body).sort()
|
||||||
status_url: `https://api.github.com/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}`,
|
return (
|
||||||
page_url: 'https://actions.github.io/is-awesome'
|
keys.length === 3 &&
|
||||||
|
keys[0] === 'artifact_url' &&
|
||||||
|
keys[1] === 'oidc_token' &&
|
||||||
|
keys[2] === 'pages_build_version' &&
|
||||||
|
body.artifact_url === 'https://fake-artifact.com&%24expand=SignedContent' &&
|
||||||
|
body.oidc_token === fakeJwt &&
|
||||||
|
body.pages_build_version === process.env.GITHUB_SHA
|
||||||
|
)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
.reply(
|
||||||
|
200,
|
||||||
|
{
|
||||||
|
status_url: `https://api.github.com/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}`,
|
||||||
|
page_url: 'https://actions.github.io/is-awesome'
|
||||||
|
},
|
||||||
|
{ headers: { 'content-type': 'application/json' } }
|
||||||
|
)
|
||||||
|
|
||||||
const deployment = new Deployment()
|
const deployment = new Deployment()
|
||||||
await deployment.create(fakeJwt)
|
await deployment.create(fakeJwt)
|
||||||
@@ -284,7 +383,6 @@ describe('Deployment', () => {
|
|||||||
)
|
)
|
||||||
|
|
||||||
artifactExchangeScope.done()
|
artifactExchangeScope.done()
|
||||||
createDeploymentScope.done()
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('warns when the timeout is greater than the maximum allowed', async () => {
|
it('warns when the timeout is greater than the maximum allowed', async () => {
|
||||||
@@ -299,19 +397,36 @@ describe('Deployment', () => {
|
|||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
const createDeploymentScope = nock('https://api.github.com')
|
mockPool
|
||||||
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, {
|
.intercept({
|
||||||
artifact_url: 'https://fake-artifact.com&%24expand=SignedContent',
|
path: `/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`,
|
||||||
pages_build_version: process.env.GITHUB_SHA,
|
method: 'POST',
|
||||||
oidc_token: fakeJwt
|
body: bodyString => {
|
||||||
})
|
const body = JSON.parse(bodyString)
|
||||||
.reply(200, {
|
const keys = Object.keys(body).sort()
|
||||||
status_url: `https://api.github.com/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}`,
|
return (
|
||||||
page_url: 'https://actions.github.io/is-awesome'
|
keys.length === 3 &&
|
||||||
|
keys[0] === 'artifact_url' &&
|
||||||
|
keys[1] === 'oidc_token' &&
|
||||||
|
keys[2] === 'pages_build_version' &&
|
||||||
|
body.artifact_url === 'https://fake-artifact.com&%24expand=SignedContent' &&
|
||||||
|
body.oidc_token === fakeJwt &&
|
||||||
|
body.pages_build_version === process.env.GITHUB_SHA
|
||||||
|
)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
.reply(
|
||||||
|
200,
|
||||||
|
{
|
||||||
|
status_url: `https://api.github.com/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}`,
|
||||||
|
page_url: 'https://actions.github.io/is-awesome'
|
||||||
|
},
|
||||||
|
{ headers: { 'content-type': 'application/json' } }
|
||||||
|
)
|
||||||
|
|
||||||
core.getIDToken = jest.fn().mockResolvedValue(fakeJwt)
|
core.getIDToken = jest.fn().mockResolvedValue(fakeJwt)
|
||||||
|
|
||||||
|
// Set timeout to greater than max
|
||||||
jest.spyOn(core, 'getInput').mockImplementation(param => {
|
jest.spyOn(core, 'getInput').mockImplementation(param => {
|
||||||
switch (param) {
|
switch (param) {
|
||||||
case 'artifact_name':
|
case 'artifact_name':
|
||||||
@@ -333,7 +448,6 @@ describe('Deployment', () => {
|
|||||||
)
|
)
|
||||||
|
|
||||||
artifactExchangeScope.done()
|
artifactExchangeScope.done()
|
||||||
createDeploymentScope.done()
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -350,22 +464,39 @@ describe('Deployment', () => {
|
|||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
const createDeploymentScope = nock('https://api.github.com')
|
mockPool
|
||||||
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, {
|
.intercept({
|
||||||
artifact_url: 'https://fake-artifact.com&%24expand=SignedContent',
|
path: `/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`,
|
||||||
pages_build_version: process.env.GITHUB_SHA,
|
method: 'POST',
|
||||||
oidc_token: fakeJwt
|
body: bodyString => {
|
||||||
})
|
const body = JSON.parse(bodyString)
|
||||||
.reply(200, {
|
const keys = Object.keys(body).sort()
|
||||||
status_url: `https://api.github.com/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}`,
|
return (
|
||||||
page_url: 'https://actions.github.io/is-awesome'
|
keys.length === 3 &&
|
||||||
|
keys[0] === 'artifact_url' &&
|
||||||
|
keys[1] === 'oidc_token' &&
|
||||||
|
keys[2] === 'pages_build_version' &&
|
||||||
|
body.artifact_url === 'https://fake-artifact.com&%24expand=SignedContent' &&
|
||||||
|
body.oidc_token === fakeJwt &&
|
||||||
|
body.pages_build_version === process.env.GITHUB_SHA
|
||||||
|
)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
.reply(
|
||||||
|
200,
|
||||||
|
{
|
||||||
|
status_url: `https://api.github.com/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}`,
|
||||||
|
page_url: 'https://actions.github.io/is-awesome'
|
||||||
|
},
|
||||||
|
{ headers: { 'content-type': 'application/json' } }
|
||||||
|
)
|
||||||
|
|
||||||
const deploymentStatusScope = nock('https://api.github.com')
|
mockPool
|
||||||
.get(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}`)
|
.intercept({
|
||||||
.reply(200, {
|
path: `/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}`,
|
||||||
status: 'succeed'
|
method: 'GET'
|
||||||
})
|
})
|
||||||
|
.reply(200, { status: 'succeed' }, { headers: { 'content-type': 'application/json' } })
|
||||||
|
|
||||||
core.getIDToken = jest.fn().mockResolvedValue(fakeJwt)
|
core.getIDToken = jest.fn().mockResolvedValue(fakeJwt)
|
||||||
|
|
||||||
@@ -378,8 +509,6 @@ describe('Deployment', () => {
|
|||||||
expect(core.info).toHaveBeenLastCalledWith('Reported success!')
|
expect(core.info).toHaveBeenLastCalledWith('Reported success!')
|
||||||
|
|
||||||
artifactExchangeScope.done()
|
artifactExchangeScope.done()
|
||||||
createDeploymentScope.done()
|
|
||||||
deploymentStatusScope.done()
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('fails check when no deployment is found', async () => {
|
it('fails check when no deployment is found', async () => {
|
||||||
@@ -401,16 +530,32 @@ describe('Deployment', () => {
|
|||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
const createDeploymentScope = nock('https://api.github.com')
|
mockPool
|
||||||
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, {
|
.intercept({
|
||||||
artifact_url: 'https://fake-artifact.com&%24expand=SignedContent',
|
path: `/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`,
|
||||||
pages_build_version: process.env.GITHUB_SHA,
|
method: 'POST',
|
||||||
oidc_token: fakeJwt
|
body: bodyString => {
|
||||||
})
|
const body = JSON.parse(bodyString)
|
||||||
.reply(200, {
|
const keys = Object.keys(body).sort()
|
||||||
status_url: `https://api.github.com/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}`,
|
return (
|
||||||
page_url: 'https://actions.github.io/is-awesome'
|
keys.length === 3 &&
|
||||||
|
keys[0] === 'artifact_url' &&
|
||||||
|
keys[1] === 'oidc_token' &&
|
||||||
|
keys[2] === 'pages_build_version' &&
|
||||||
|
body.artifact_url === 'https://fake-artifact.com&%24expand=SignedContent' &&
|
||||||
|
body.oidc_token === fakeJwt &&
|
||||||
|
body.pages_build_version === process.env.GITHUB_SHA
|
||||||
|
)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
.reply(
|
||||||
|
200,
|
||||||
|
{
|
||||||
|
status_url: `https://api.github.com/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}`,
|
||||||
|
page_url: 'https://actions.github.io/is-awesome'
|
||||||
|
},
|
||||||
|
{ headers: { 'content-type': 'application/json' } }
|
||||||
|
)
|
||||||
|
|
||||||
core.getIDToken = jest.fn().mockResolvedValue(fakeJwt)
|
core.getIDToken = jest.fn().mockResolvedValue(fakeJwt)
|
||||||
|
|
||||||
@@ -421,9 +566,9 @@ describe('Deployment', () => {
|
|||||||
expect(core.setFailed).toBeCalledWith('Unable to get deployment status.')
|
expect(core.setFailed).toBeCalledWith('Unable to get deployment status.')
|
||||||
|
|
||||||
artifactExchangeScope.done()
|
artifactExchangeScope.done()
|
||||||
createDeploymentScope.done()
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// TODO: Fix! Consistently fails.
|
||||||
it('enforces max timeout', async () => {
|
it('enforces max timeout', async () => {
|
||||||
process.env.GITHUB_SHA = 'valid-build-version'
|
process.env.GITHUB_SHA = 'valid-build-version'
|
||||||
|
|
||||||
@@ -436,24 +581,51 @@ describe('Deployment', () => {
|
|||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
const createDeploymentScope = nock('https://api.github.com')
|
mockPool
|
||||||
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, {
|
.intercept({
|
||||||
artifact_url: 'https://fake-artifact.com&%24expand=SignedContent',
|
path: `/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`,
|
||||||
pages_build_version: process.env.GITHUB_SHA,
|
method: 'POST',
|
||||||
oidc_token: fakeJwt
|
body: bodyString => {
|
||||||
})
|
const body = JSON.parse(bodyString)
|
||||||
.reply(200, {
|
const keys = Object.keys(body).sort()
|
||||||
status_url: `https://api.github.com/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}`,
|
return (
|
||||||
page_url: 'https://actions.github.io/is-awesome'
|
keys.length === 3 &&
|
||||||
|
keys[0] === 'artifact_url' &&
|
||||||
|
keys[1] === 'oidc_token' &&
|
||||||
|
keys[2] === 'pages_build_version' &&
|
||||||
|
body.artifact_url === 'https://fake-artifact.com&%24expand=SignedContent' &&
|
||||||
|
body.oidc_token === fakeJwt &&
|
||||||
|
body.pages_build_version === process.env.GITHUB_SHA
|
||||||
|
)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
.reply(
|
||||||
|
200,
|
||||||
|
{
|
||||||
|
status_url: `https://api.github.com/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}`,
|
||||||
|
page_url: 'https://actions.github.io/is-awesome'
|
||||||
|
},
|
||||||
|
{ headers: { 'content-type': 'application/json' } }
|
||||||
|
)
|
||||||
|
|
||||||
const cancelDeploymentScope = nock('https://api.github.com')
|
mockPool
|
||||||
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}/cancel`)
|
.intercept({
|
||||||
.reply(200, {})
|
path: `/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}`,
|
||||||
|
method: 'GET'
|
||||||
|
})
|
||||||
|
.reply(200, { status: 'deployment_in_progress' }, { headers: { 'content-type': 'application/json' } })
|
||||||
|
.times(2)
|
||||||
|
|
||||||
|
mockPool
|
||||||
|
.intercept({
|
||||||
|
path: `/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}/cancel`,
|
||||||
|
method: 'POST'
|
||||||
|
})
|
||||||
|
.reply(200, {}, { headers: { 'content-type': 'application/json' } })
|
||||||
|
|
||||||
core.getIDToken = jest.fn().mockResolvedValue(fakeJwt)
|
core.getIDToken = jest.fn().mockResolvedValue(fakeJwt)
|
||||||
|
|
||||||
// Set timeout to great than max
|
// Set timeout to greater than max
|
||||||
jest.spyOn(core, 'getInput').mockImplementation(param => {
|
jest.spyOn(core, 'getInput').mockImplementation(param => {
|
||||||
switch (param) {
|
switch (param) {
|
||||||
case 'artifact_name':
|
case 'artifact_name':
|
||||||
@@ -462,6 +634,8 @@ describe('Deployment', () => {
|
|||||||
return process.env.GITHUB_TOKEN
|
return process.env.GITHUB_TOKEN
|
||||||
case 'error_count':
|
case 'error_count':
|
||||||
return 10
|
return 10
|
||||||
|
// case 'reporting_interval':
|
||||||
|
// return 50 // The default of 5000 is too long for the test
|
||||||
case 'timeout':
|
case 'timeout':
|
||||||
return MAX_TIMEOUT + 1
|
return MAX_TIMEOUT + 1
|
||||||
default:
|
default:
|
||||||
@@ -475,6 +649,7 @@ describe('Deployment', () => {
|
|||||||
.spyOn(Date, 'now')
|
.spyOn(Date, 'now')
|
||||||
.mockImplementationOnce(() => mockStartTime)
|
.mockImplementationOnce(() => mockStartTime)
|
||||||
.mockImplementationOnce(() => now)
|
.mockImplementationOnce(() => now)
|
||||||
|
.mockImplementationOnce(() => now + MAX_TIMEOUT)
|
||||||
|
|
||||||
// Create the deployment
|
// Create the deployment
|
||||||
const deployment = new Deployment()
|
const deployment = new Deployment()
|
||||||
@@ -486,8 +661,6 @@ describe('Deployment', () => {
|
|||||||
expect(core.setFailed).toBeCalledWith('Timeout reached, aborting!')
|
expect(core.setFailed).toBeCalledWith('Timeout reached, aborting!')
|
||||||
|
|
||||||
artifactExchangeScope.done()
|
artifactExchangeScope.done()
|
||||||
createDeploymentScope.done()
|
|
||||||
cancelDeploymentScope.done()
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('sets timeout to user timeout if user timeout is less than max timeout', async () => {
|
it('sets timeout to user timeout if user timeout is less than max timeout', async () => {
|
||||||
@@ -502,24 +675,43 @@ describe('Deployment', () => {
|
|||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
const createDeploymentScope = nock('https://api.github.com')
|
mockPool
|
||||||
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, {
|
.intercept({
|
||||||
artifact_url: 'https://fake-artifact.com&%24expand=SignedContent',
|
path: `/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`,
|
||||||
pages_build_version: process.env.GITHUB_SHA,
|
method: 'POST',
|
||||||
oidc_token: fakeJwt
|
body: bodyString => {
|
||||||
})
|
const body = JSON.parse(bodyString)
|
||||||
.reply(200, {
|
const keys = Object.keys(body).sort()
|
||||||
status_url: `https://api.github.com/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}`,
|
return (
|
||||||
page_url: 'https://actions.github.io/is-awesome'
|
keys.length === 3 &&
|
||||||
|
keys[0] === 'artifact_url' &&
|
||||||
|
keys[1] === 'oidc_token' &&
|
||||||
|
keys[2] === 'pages_build_version' &&
|
||||||
|
body.artifact_url === 'https://fake-artifact.com&%24expand=SignedContent' &&
|
||||||
|
body.oidc_token === fakeJwt &&
|
||||||
|
body.pages_build_version === process.env.GITHUB_SHA
|
||||||
|
)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
.reply(
|
||||||
|
200,
|
||||||
|
{
|
||||||
|
status_url: `https://api.github.com/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}`,
|
||||||
|
page_url: 'https://actions.github.io/is-awesome'
|
||||||
|
},
|
||||||
|
{ headers: { 'content-type': 'application/json' } }
|
||||||
|
)
|
||||||
|
|
||||||
const cancelDeploymentScope = nock('https://api.github.com')
|
mockPool
|
||||||
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}/cancel`)
|
.intercept({
|
||||||
.reply(200, {})
|
path: `/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}/cancel`,
|
||||||
|
method: 'POST'
|
||||||
|
})
|
||||||
|
.reply(200, {}, { headers: { 'content-type': 'application/json' } })
|
||||||
|
|
||||||
core.getIDToken = jest.fn().mockResolvedValue(fakeJwt)
|
core.getIDToken = jest.fn().mockResolvedValue(fakeJwt)
|
||||||
|
|
||||||
// Set timeout to great than max
|
// Set timeout to greater than max
|
||||||
jest.spyOn(core, 'getInput').mockImplementation(param => {
|
jest.spyOn(core, 'getInput').mockImplementation(param => {
|
||||||
switch (param) {
|
switch (param) {
|
||||||
case 'artifact_name':
|
case 'artifact_name':
|
||||||
@@ -552,10 +744,9 @@ describe('Deployment', () => {
|
|||||||
expect(core.setFailed).toBeCalledWith('Timeout reached, aborting!')
|
expect(core.setFailed).toBeCalledWith('Timeout reached, aborting!')
|
||||||
|
|
||||||
artifactExchangeScope.done()
|
artifactExchangeScope.done()
|
||||||
createDeploymentScope.done()
|
|
||||||
cancelDeploymentScope.done()
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// TODO: Intermittently fails if the other test does
|
||||||
it('sets output to success when timeout is set but not reached', async () => {
|
it('sets output to success when timeout is set but not reached', async () => {
|
||||||
process.env.GITHUB_SHA = 'valid-build-version'
|
process.env.GITHUB_SHA = 'valid-build-version'
|
||||||
|
|
||||||
@@ -568,26 +759,43 @@ describe('Deployment', () => {
|
|||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
const createDeploymentScope = nock('https://api.github.com')
|
mockPool
|
||||||
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, {
|
.intercept({
|
||||||
artifact_url: 'https://fake-artifact.com&%24expand=SignedContent',
|
path: `/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`,
|
||||||
pages_build_version: process.env.GITHUB_SHA,
|
method: 'POST',
|
||||||
oidc_token: fakeJwt
|
body: bodyString => {
|
||||||
})
|
const body = JSON.parse(bodyString)
|
||||||
.reply(200, {
|
const keys = Object.keys(body).sort()
|
||||||
status_url: `https://api.github.com/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}`,
|
return (
|
||||||
page_url: 'https://actions.github.io/is-awesome'
|
keys.length === 3 &&
|
||||||
|
keys[0] === 'artifact_url' &&
|
||||||
|
keys[1] === 'oidc_token' &&
|
||||||
|
keys[2] === 'pages_build_version' &&
|
||||||
|
body.artifact_url === 'https://fake-artifact.com&%24expand=SignedContent' &&
|
||||||
|
body.oidc_token === fakeJwt &&
|
||||||
|
body.pages_build_version === process.env.GITHUB_SHA
|
||||||
|
)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
.reply(
|
||||||
|
200,
|
||||||
|
{
|
||||||
|
status_url: `https://api.github.com/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}`,
|
||||||
|
page_url: 'https://actions.github.io/is-awesome'
|
||||||
|
},
|
||||||
|
{ headers: { 'content-type': 'application/json' } }
|
||||||
|
)
|
||||||
|
|
||||||
const deploymentStatusScope = nock('https://api.github.com')
|
mockPool
|
||||||
.get(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}`)
|
.intercept({
|
||||||
.reply(200, {
|
path: `/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}`,
|
||||||
status: 'succeed'
|
method: 'GET'
|
||||||
})
|
})
|
||||||
|
.reply(200, { status: 'succeed' }, { headers: { 'content-type': 'application/json' } })
|
||||||
|
|
||||||
core.getIDToken = jest.fn().mockResolvedValue(fakeJwt)
|
core.getIDToken = jest.fn().mockResolvedValue(fakeJwt)
|
||||||
|
|
||||||
// Set timeout to great than max
|
// Set timeout to greater than max
|
||||||
jest.spyOn(core, 'getInput').mockImplementation(param => {
|
jest.spyOn(core, 'getInput').mockImplementation(param => {
|
||||||
switch (param) {
|
switch (param) {
|
||||||
case 'artifact_name':
|
case 'artifact_name':
|
||||||
@@ -604,7 +812,7 @@ describe('Deployment', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
const now = Date.now()
|
const now = Date.now()
|
||||||
const mockStartTime = now
|
const mockStartTime = now // No time elapsed
|
||||||
jest
|
jest
|
||||||
.spyOn(Date, 'now')
|
.spyOn(Date, 'now')
|
||||||
.mockImplementationOnce(() => mockStartTime)
|
.mockImplementationOnce(() => mockStartTime)
|
||||||
@@ -621,8 +829,6 @@ describe('Deployment', () => {
|
|||||||
expect(core.info).toHaveBeenLastCalledWith('Reported success!')
|
expect(core.info).toHaveBeenLastCalledWith('Reported success!')
|
||||||
|
|
||||||
artifactExchangeScope.done()
|
artifactExchangeScope.done()
|
||||||
createDeploymentScope.done()
|
|
||||||
deploymentStatusScope.done()
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -639,20 +845,39 @@ describe('Deployment', () => {
|
|||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
const createDeploymentScope = nock('https://api.github.com')
|
mockPool
|
||||||
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, {
|
.intercept({
|
||||||
artifact_url: 'https://fake-artifact.com&%24expand=SignedContent',
|
path: `/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`,
|
||||||
pages_build_version: process.env.GITHUB_SHA,
|
method: 'POST',
|
||||||
oidc_token: fakeJwt
|
body: bodyString => {
|
||||||
})
|
const body = JSON.parse(bodyString)
|
||||||
.reply(200, {
|
const keys = Object.keys(body).sort()
|
||||||
status_url: `https://api.github.com/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}`,
|
return (
|
||||||
page_url: 'https://actions.github.io/is-awesome'
|
keys.length === 3 &&
|
||||||
|
keys[0] === 'artifact_url' &&
|
||||||
|
keys[1] === 'oidc_token' &&
|
||||||
|
keys[2] === 'pages_build_version' &&
|
||||||
|
body.artifact_url === 'https://fake-artifact.com&%24expand=SignedContent' &&
|
||||||
|
body.oidc_token === fakeJwt &&
|
||||||
|
body.pages_build_version === process.env.GITHUB_SHA
|
||||||
|
)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
.reply(
|
||||||
|
200,
|
||||||
|
{
|
||||||
|
status_url: `https://api.github.com/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}`,
|
||||||
|
page_url: 'https://actions.github.io/is-awesome'
|
||||||
|
},
|
||||||
|
{ headers: { 'content-type': 'application/json' } }
|
||||||
|
)
|
||||||
|
|
||||||
const cancelDeploymentScope = nock('https://api.github.com')
|
mockPool
|
||||||
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}/cancel`)
|
.intercept({
|
||||||
.reply(200, {})
|
path: `/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}/cancel`,
|
||||||
|
method: 'POST'
|
||||||
|
})
|
||||||
|
.reply(200, {}, { headers: { 'content-type': 'application/json' } })
|
||||||
|
|
||||||
core.getIDToken = jest.fn().mockResolvedValue(fakeJwt)
|
core.getIDToken = jest.fn().mockResolvedValue(fakeJwt)
|
||||||
|
|
||||||
@@ -666,8 +891,6 @@ describe('Deployment', () => {
|
|||||||
expect(core.info).toHaveBeenLastCalledWith(`Canceled deployment with ID ${process.env.GITHUB_SHA}`)
|
expect(core.info).toHaveBeenLastCalledWith(`Canceled deployment with ID ${process.env.GITHUB_SHA}`)
|
||||||
|
|
||||||
artifactExchangeScope.done()
|
artifactExchangeScope.done()
|
||||||
createDeploymentScope.done()
|
|
||||||
cancelDeploymentScope.done()
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('can exit if a pages deployment was not created and none need to be cancelled', async () => {
|
it('can exit if a pages deployment was not created and none need to be cancelled', async () => {
|
||||||
@@ -695,21 +918,39 @@ describe('Deployment', () => {
|
|||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
const createDeploymentScope = nock('https://api.github.com')
|
mockPool
|
||||||
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, {
|
.intercept({
|
||||||
artifact_url: 'https://fake-artifact.com&%24expand=SignedContent',
|
path: `/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`,
|
||||||
pages_build_version: process.env.GITHUB_SHA,
|
method: 'POST',
|
||||||
oidc_token: fakeJwt
|
body: bodyString => {
|
||||||
})
|
const body = JSON.parse(bodyString)
|
||||||
.reply(200, {
|
const keys = Object.keys(body).sort()
|
||||||
status_url: `https://api.github.com/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}`,
|
return (
|
||||||
page_url: 'https://actions.github.io/is-awesome'
|
keys.length === 3 &&
|
||||||
|
keys[0] === 'artifact_url' &&
|
||||||
|
keys[1] === 'oidc_token' &&
|
||||||
|
keys[2] === 'pages_build_version' &&
|
||||||
|
body.artifact_url === 'https://fake-artifact.com&%24expand=SignedContent' &&
|
||||||
|
body.oidc_token === fakeJwt &&
|
||||||
|
body.pages_build_version === process.env.GITHUB_SHA
|
||||||
|
)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
.reply(
|
||||||
|
200,
|
||||||
|
{
|
||||||
|
status_url: `https://api.github.com/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}`,
|
||||||
|
page_url: 'https://actions.github.io/is-awesome'
|
||||||
|
},
|
||||||
|
{ headers: { 'content-type': 'application/json' } }
|
||||||
|
)
|
||||||
|
|
||||||
// nock will throw an error every time it tries to cancel the deployment
|
mockPool
|
||||||
const cancelDeploymentScope = nock('https://api.github.com')
|
.intercept({
|
||||||
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}/cancel`)
|
path: `/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}/cancel`,
|
||||||
.reply(500, {})
|
method: 'POST'
|
||||||
|
})
|
||||||
|
.reply(500, {}, { headers: { 'content-type': 'application/json' } })
|
||||||
|
|
||||||
core.getIDToken = jest.fn().mockResolvedValue(fakeJwt)
|
core.getIDToken = jest.fn().mockResolvedValue(fakeJwt)
|
||||||
|
|
||||||
@@ -723,8 +964,6 @@ describe('Deployment', () => {
|
|||||||
expect(core.error).toHaveBeenCalledWith(`Canceling Pages deployment failed`, expect.anything())
|
expect(core.error).toHaveBeenCalledWith(`Canceling Pages deployment failed`, expect.anything())
|
||||||
|
|
||||||
artifactExchangeScope.done()
|
artifactExchangeScope.done()
|
||||||
createDeploymentScope.done()
|
|
||||||
cancelDeploymentScope.done()
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user