Skip to content

Commit

Permalink
Add nested Poetry projects test
Browse files Browse the repository at this point in the history
  • Loading branch information
oranav committed Oct 10, 2022
1 parent 98a834f commit f6e0835
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 9 deletions.
62 changes: 53 additions & 9 deletions __tests__/cache-restore.test.ts
@@ -1,8 +1,10 @@
import * as path from 'path';
import * as core from '@actions/core';
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', () => {
Expand All @@ -13,7 +15,7 @@ describe('restore-cache', () => {
const requirementsLinuxHash =
'2d0ff7f46b0e120e3d3294db65768b474934242637b9899b873e6283dfd16d7c';
const poetryLockHash =
'571bf984f8d210e6a97f854e479fdd4a2b5af67b5fdac109ec337a0ea16e7836';
'f24ea1ad73968e6c8d80c16a093ade72d9332c433aeef979a0dd943e6a99b2ab';
const poetryConfigOutput = `
cache-dir = "/Users/patrick/Library/Caches/pypoetry"
experimental.new-installer = false
Expand Down Expand Up @@ -99,21 +101,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',
path.join(__dirname, 'data', 'inner', '.venv'),
path.join(__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,
Expand All @@ -128,6 +165,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}`
Expand Down
1 change: 1 addition & 0 deletions __tests__/data/inner/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions __tests__/data/inner/pyproject.toml

0 comments on commit f6e0835

Please sign in to comment.