diff --git a/__tests__/cache-restore.test.ts b/__tests__/cache-restore.test.ts index 08cf90f92..c623483fe 100644 --- a/__tests__/cache-restore.test.ts +++ b/__tests__/cache-restore.test.ts @@ -3,6 +3,7 @@ import * as cache from '@actions/cache'; import * as exec from '@actions/exec'; import * as io from '@actions/io'; import {getCacheDistributor} from '../src/cache-distributions/cache-factory'; +import {State} from '../src/cache-distributions/cache-distributor'; import * as utils from './../src/utils'; describe('restore-cache', () => { @@ -13,7 +14,7 @@ describe('restore-cache', () => { const requirementsLinuxHash = '2d0ff7f46b0e120e3d3294db65768b474934242637b9899b873e6283dfd16d7c'; const poetryLockHash = - '571bf984f8d210e6a97f854e479fdd4a2b5af67b5fdac109ec337a0ea16e7836'; + 'f24ea1ad73968e6c8d80c16a093ade72d9332c433aeef979a0dd943e6a99b2ab'; const poetryConfigOutput = ` cache-dir = "/Users/patrick/Library/Caches/pypoetry" experimental.new-installer = false @@ -99,21 +100,56 @@ virtualenvs.path = "{cache-dir}/virtualenvs" # /Users/patrick/Library/Caches/py describe('Restore dependencies', () => { it.each([ - ['pip', '3.8.12', undefined, requirementsHash], - ['pip', '3.8.12', '**/requirements-linux.txt', requirementsLinuxHash], + ['pip', '3.8.12', undefined, requirementsHash, undefined], + [ + 'pip', + '3.8.12', + '**/requirements-linux.txt', + requirementsLinuxHash, + undefined + ], [ 'pip', '3.8.12', '__tests__/data/requirements-linux.txt', - requirementsLinuxHash + requirementsLinuxHash, + undefined ], - ['pip', '3.8.12', '__tests__/data/requirements.txt', requirementsHash], - ['pipenv', '3.9.1', undefined, pipFileLockHash], - ['pipenv', '3.9.12', '__tests__/data/requirements.txt', requirementsHash], - ['poetry', '3.9.1', undefined, poetryLockHash] + [ + 'pip', + '3.8.12', + '__tests__/data/requirements.txt', + requirementsHash, + undefined + ], + ['pipenv', '3.9.1', undefined, pipFileLockHash, undefined], + [ + 'pipenv', + '3.9.12', + '__tests__/data/requirements.txt', + requirementsHash, + undefined + ], + [ + 'poetry', + '3.9.1', + undefined, + poetryLockHash, + [ + '/Users/patrick/Library/Caches/pypoetry/virtualenvs', + `${__dirname}/data/inner/.venv`, + `${__dirname}/data/.venv` + ] + ] ])( 'restored dependencies for %s by primaryKey', - async (packageManager, pythonVersion, dependencyFile, fileHash) => { + async ( + packageManager, + pythonVersion, + dependencyFile, + fileHash, + cachePaths + ) => { const cacheDistributor = getCacheDistributor( packageManager, pythonVersion, @@ -128,6 +164,13 @@ virtualenvs.path = "{cache-dir}/virtualenvs" # /Users/patrick/Library/Caches/py await cacheDistributor.restoreCache(); + if (cachePaths !== undefined) { + expect(saveStateSpy).toHaveBeenCalledWith( + State.CACHE_PATHS, + cachePaths + ); + } + if (process.platform === 'linux' && packageManager === 'pip') { expect(infoSpy).toHaveBeenCalledWith( `Cache restored from key: setup-python-${process.env['RUNNER_OS']}-Ubuntu-20.4-python-${pythonVersion}-${packageManager}-${fileHash}` diff --git a/__tests__/data/inner/poetry.lock b/__tests__/data/inner/poetry.lock new file mode 120000 index 000000000..99fe86c2a --- /dev/null +++ b/__tests__/data/inner/poetry.lock @@ -0,0 +1 @@ +../poetry.lock \ No newline at end of file diff --git a/__tests__/data/inner/pyproject.toml b/__tests__/data/inner/pyproject.toml new file mode 120000 index 000000000..1e11d7825 --- /dev/null +++ b/__tests__/data/inner/pyproject.toml @@ -0,0 +1 @@ +../pyproject.toml \ No newline at end of file