make main.test.ts test data more varied

This commit is contained in:
boxofyellow
2024-01-26 16:34:40 +00:00
committed by ddivad195
parent c88b93864f
commit c06282fe29
+12 -12
View File
@@ -69,7 +69,7 @@ describe('action', () => {
it('fails if event is not a release', async () => {
// Mock the environment
process.env.GITHUB_REPOSITORY = 'test/test'
process.env.GITHUB_REPOSITORY = 'test-org/test-repo'
github.context.eventName = 'push'
// Run the action
@@ -83,7 +83,7 @@ describe('action', () => {
it('fails if release tag is not a valid semantic version', async () => {
// Mock the environment
process.env.GITHUB_REPOSITORY = 'test/test'
process.env.GITHUB_REPOSITORY = 'test-org/test-repo'
github.context.eventName = 'release'
github.context.payload = {
release: {
@@ -103,12 +103,12 @@ describe('action', () => {
it('fails if multiple paths are provided and staging files fails', async () => {
// Mock the environment
process.env.GITHUB_REPOSITORY = 'test/test'
process.env.GITHUB_REPOSITORY = 'test-org/test-repo'
github.context.eventName = 'release'
github.context.payload = {
release: {
id: '123',
tag_name: 'v1.0.0'
tag_name: 'v1.2.3'
}
}
getInputMock.mockImplementation((name: string) => {
@@ -135,12 +135,12 @@ describe('action', () => {
it('fails if an error is thrown from dependent code', async () => {
// Mock the environment
process.env.GITHUB_REPOSITORY = 'test/test'
process.env.GITHUB_REPOSITORY = 'test-org/test-repo'
github.context.eventName = 'release'
github.context.payload = {
release: {
id: '123',
tag_name: 'v1.0.0'
tag_name: 'v1.2.3'
}
}
getInputMock.mockImplementation((name: string) => {
@@ -172,22 +172,22 @@ describe('action', () => {
})
it('successfully uploads if the release tag is a semver without v prefix', async () => {
await testHappyPath('1.0.0', 'test')
await testHappyPath('1.2.3', 'test')
})
it('successfully uploads if the release tag is a semver with v prefix', async () => {
await testHappyPath('v1.0.0', 'test')
await testHappyPath('v1.2.3', 'test')
})
it('successfully uploads if multiple paths are provided', async () => {
await testHappyPath('v1.0.0', 'test test2')
await testHappyPath('v1.2.3', 'test test2')
})
})
// Test that main successfully uploads and returns the manifest & package URL
async function testHappyPath(version: string, path: string): Promise<void> {
// Mock the environment
process.env.GITHUB_REPOSITORY = 'test/test'
process.env.GITHUB_REPOSITORY = 'test-org/test-repo'
github.context.eventName = 'release'
github.context.payload = {
release: {
@@ -228,7 +228,7 @@ async function testHappyPath(version: string, path: string): Promise<void> {
})
publishOCIArtifactMock.mockImplementation(() => {
return new URL('https://ghcr.io/v2/test/test:1.0.0')
return new URL('https://ghcr.io/v2/test-org/test-repo:1.2.3')
})
// Run the action
@@ -239,7 +239,7 @@ async function testHappyPath(version: string, path: string): Promise<void> {
// Check manifest is in output
expect(setOutputMock).toHaveBeenCalledWith(
'package-url',
'https://ghcr.io/v2/test/test:1.0.0'
'https://ghcr.io/v2/test-org/test-repo:1.2.3'
)
expect(setOutputMock).toHaveBeenCalledWith(
'package-manifest',