Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix race condition #195

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions __tests__/actions/mainAction.test.ts
Expand Up @@ -4,7 +4,7 @@ import {mainAction} from '../../src/actions'

jest.mock('../../src/cache', () => {
return {
cache: jest.fn(),
restore: jest.fn(),
restoreFactory: jest.fn().mockReturnValue(jest.fn())
}
})
Expand Down Expand Up @@ -43,7 +43,7 @@ describe('main action', () => {
})

test('runs', async () => {
const cacheMock = jest.spyOn(cache, 'cache')
const cacheMock = jest.spyOn(cache, 'restore')
const composerInstallMock = jest.spyOn(composer, 'install')
const mockFactory = cache.restoreFactory()

Expand All @@ -69,7 +69,7 @@ describe('main action', () => {


test('runs with a different working directory', async () => {
const cacheMock = jest.spyOn(cache, 'cache')
const cacheMock = jest.spyOn(cache, 'restore')
const composerInstallMock = jest.spyOn(composer, 'install')
const mockFactory = cache.restoreFactory()

Expand All @@ -94,7 +94,7 @@ describe('main action', () => {
})

test('sets failure state with error', async () => {
const cacheMock = jest.spyOn(cache, 'cache').mockRejectedValue({
const cacheMock = jest.spyOn(cache, 'restore').mockRejectedValue({
message: 'a mocked error message'
})
const composerInstallMock = jest.spyOn(composer, 'install')
Expand Down
10 changes: 4 additions & 6 deletions __tests__/actions/postAction.test.ts
Expand Up @@ -3,7 +3,7 @@ import {postAction} from '../../src/actions'

jest.mock('../../src/cache', () => {
return {
cache: jest.fn(),
save: jest.fn(),
saveFactory: jest.fn().mockReturnValue(jest.fn())
}
})
Expand Down Expand Up @@ -36,7 +36,7 @@ describe('post action', () => {
})

test('runs', async () => {
const cacheMock = jest.spyOn(cache, 'cache')
const cacheMock = jest.spyOn(cache, 'save')
const mockFactory = cache.saveFactory()

process.env['INPUT_COMPOSER-OPTIONS'] = ''
Expand All @@ -49,12 +49,11 @@ describe('post action', () => {
mockFactory,
['/path/to/composer/cache'],
'cache-key-mock',
['cache-key-', 'cache-']
)
})

test('runs with a custom working-directory', async () => {
const cacheMock = jest.spyOn(cache, 'cache')
const cacheMock = jest.spyOn(cache, 'save')
const mockFactory = cache.saveFactory()

process.env['INPUT_COMPOSER-OPTIONS'] = ' --working-dir subdirectory'
Expand All @@ -67,12 +66,11 @@ describe('post action', () => {
mockFactory,
['/path/to/composer/cache'],
'cache-key-mock',
['cache-key-', 'cache-']
)
})

test('sets failure state with error', async () => {
const cacheMock = jest.spyOn(cache, 'cache').mockRejectedValue({
const cacheMock = jest.spyOn(cache, 'save').mockRejectedValue({
message: 'a mocked error message'
})

Expand Down
10 changes: 1 addition & 9 deletions __tests__/cache/cache.test.ts
Expand Up @@ -15,21 +15,13 @@ describe('cache', () => {
test('calls the factory()', async () => {
const mockFactory = jest.fn()

await cache.cache(
await cache.restore(
mockFactory,
['/path/to/cache1', '/path/to/cache2'],
'primary-cache-key',
['primary-cache-', 'primary-']
)

expect(mockFactory).toHaveBeenCalledTimes(1)

expect(process.env['INPUT_PATH']).toEqual(
`/path/to/cache1\n/path/to/cache2`
)
expect(process.env['INPUT_KEY']).toEqual(`primary-cache-key`)
expect(process.env['INPUT_RESTORE-KEYS']).toEqual(
`primary-cache-\nprimary-`
)
})
})