8000 Add tests · Ditto190/Github-setup-python@1259541 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1259541

Browse files
committed
Add tests
1 parent 95824fd commit 1259541

File tree

3 files changed

+447
-10
lines changed

3 files changed

+447
-10
lines changed

__tests__/cache-restore.test.ts

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ describe('restore-cache', () => {
1010
'd8110e0006d7fb5ee76365d565eef9d37df1d11598b912d3eb66d398d57a1121';
1111
const requirementsLinuxHash =
1212
'2d0ff7f46b0e120e3d3294db65768b474934242637b9899b873e6283dfd16d7c';
13+
const poetryLockHash = '571bf984f8d210e6a97f854e479fdd4a2b5af67b5fdac109ec337a0ea16e7836';
14+
const poetryConfigOutput = `
15+
cache-dir = "/Users/patrick/Library/Caches/pypoetry"
16+
experimental.new-installer = false
17+
installer.parallel = true
18+
virtualenvs.create = true
19+
virtualenvs.in-project = true
20+
virtualenvs.path = "{cache-dir}/virtualenvs" # /Users/patrick/Library/Caches/pypoetry/virtualenvs
21+
`;
1322

1423
// core spy
1524
let infoSpy: jest.SpyInstance;
@@ -47,6 +56,9 @@ describe('restore-cache', () => {
4756
if (input.includes('pip')) {
4857
return {stdout: 'pip', stderr: '', exitCode: 0};
4958
}
59+
if (input.includes('poetry')) {
60+
return {stdout: poetryConfigOutput, stderr: '', exitCode: 0};
61+
}
5062

5163
return {stdout: '', stderr: 'Error occured', exitCode: 2};
5264
});
@@ -82,7 +94,8 @@ describe('restore-cache', () => {
8294
],
8395
['pip', '3.8.12', '__tests__/data/requirements.txt', requirementsHash],
8496
['pipenv', '3.9.1', undefined, pipFileLockHash],
85-
['pipenv', '3.9.12', '__tests__/data/requirements.txt', requirementsHash]
97+
['pipenv', '3.9.12', '__tests__/data/requirements.txt', requirementsHash],
98+
['poetry', '3.9.1', undefined, poetryLockHash]
8699
])(
87100
'restored dependencies for %s by primaryKey',
88101
async (packageManager, pythonVersion, dependencyFile, fileHash) => {
@@ -138,7 +151,8 @@ describe('restore-cache', () => {
138151
],
139152
['pip', '3.8.12', '__tests__/data/requirements.txt', pipFileLockHash],
140153
['pipenv', '3.9.1', undefined, requirementsHash],
141-
['pipenv', '3.9.12', '__tests__/data/requirements.txt', requirementsHash]
154+
['pipenv', '3.9.12', '__tests__/data/requirements.txt', requirementsHash],
155+
['poetry', '3.9.1', undefined, requirementsHash]
142156
])(
143157
'restored dependencies for %s by primaryKey',
144158
async (packageManager, pythonVersion, dependencyFile, fileHash) => {
@@ -154,10 +168,17 @@ describe('restore-cache', () => {
154168
);
155169
await cacheDistributor.restoreCache();
156170
let result = '';
157-
if (packageManager !== 'pipenv') {
158-
result = `Cache restored from key: ${fileHash}`;
159-
} else {
160-
result = 'pipenv cache is not found';
171+
172+
switch (packageManager) {
173+
case 'pip':
174+
result = `Cache restored from key: ${fileHash}`;
175+
break;
176+
case 'pipenv':
177+
result = 'pipenv cache is not found';
178+
break;
179+
case 'poetry':
180+
result = 'poetry cache is not found';
181+
break;
161182
}
162183

163184
expect(infoSpy).toHaveBeenCalledWith(result);

0 commit comments

Comments
 (0)
0