Skip to content

Commit 8b96634

Browse files
authored
feat: added downloaded snapshots caching (#27)
1 parent e7e06d0 commit 8b96634

File tree

7 files changed

+150648
-97648
lines changed

7 files changed

+150648
-97648
lines changed

__tests__/installer/linux.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as path from 'path'
22
import * as exec from '@actions/exec'
3+
import * as cache from '@actions/cache'
34
import * as toolCache from '@actions/tool-cache'
45
import {coerce as parseSemVer} from 'semver'
56
import {LinuxToolchainInstaller} from '../../src/installer/linux'
@@ -34,6 +35,8 @@ describe('linux toolchain installation verification', () => {
3435
)
3536

3637
const download = path.resolve('tool', 'download', 'path')
38+
jest.spyOn(cache, 'restoreCache').mockResolvedValue(undefined)
39+
jest.spyOn(cache, 'saveCache').mockResolvedValue(1)
3740
jest.spyOn(toolCache, 'downloadTool').mockResolvedValue(download)
3841
jest.spyOn(exec, 'exec').mockResolvedValue(0)
3942
await expect(installer['download']()).resolves.toBe(download)
@@ -65,6 +68,8 @@ describe('linux toolchain installation verification', () => {
6568
const extracted = path.resolve('tool', 'extracted', 'path')
6669
const cached = path.resolve('tool', 'cached', 'path')
6770
const swiftPath = path.join(cached, 'usr', 'bin')
71+
jest.spyOn(cache, 'restoreCache').mockResolvedValue(undefined)
72+
jest.spyOn(cache, 'saveCache').mockResolvedValue(1)
6873
jest.spyOn(toolCache, 'find').mockReturnValue('')
6974
const downloadSpy = jest.spyOn(toolCache, 'downloadTool')
7075
downloadSpy.mockResolvedValue(download)

__tests__/installer/windows.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as path from 'path'
22
import {promises as fs} from 'fs'
33
import * as exec from '@actions/exec'
4+
import * as cache from '@actions/cache'
45
import * as toolCache from '@actions/tool-cache'
56
import {coerce as parseSemVer} from 'semver'
67
import {WindowsToolchainInstaller} from '../../src/installer/windows'
@@ -53,6 +54,8 @@ describe('windows toolchain installation verification', () => {
5354
stdout: JSON.stringify([visualStudio]),
5455
stderr: ''
5556
})
57+
jest.spyOn(cache, 'restoreCache').mockResolvedValue(undefined)
58+
jest.spyOn(cache, 'saveCache').mockResolvedValue(1)
5659
jest.spyOn(toolCache, 'downloadTool').mockResolvedValue(download)
5760
jest.spyOn(exec, 'exec').mockResolvedValue(0)
5861
await expect(installer['download']()).resolves.toBe(`${download}.exe`)

__tests__/installer/xcode.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as path from 'path'
22
import {promises as fs} from 'fs'
33
import * as exec from '@actions/exec'
4+
import * as cache from '@actions/cache'
45
import * as toolCache from '@actions/tool-cache'
56
import {coerce as parseSemVer} from 'semver'
67
import * as plist from 'plist'
@@ -56,6 +57,8 @@ describe('macOS toolchain installation verification', () => {
5657

5758
const download = path.resolve('tool', 'download', 'path')
5859
jest.spyOn(installer, 'isInstallationNeeded').mockResolvedValue(true)
60+
jest.spyOn(cache, 'restoreCache').mockResolvedValue(undefined)
61+
jest.spyOn(cache, 'saveCache').mockResolvedValue(1)
5962
jest.spyOn(toolCache, 'downloadTool').mockResolvedValue(download)
6063
jest.spyOn(exec, 'exec').mockResolvedValue(0)
6164
await expect(installer['download']()).resolves.toBe(download)
@@ -95,6 +98,8 @@ describe('macOS toolchain installation verification', () => {
9598
const swiftPath = path.join(cached, 'usr', 'bin')
9699
const identifier = 'org.swift.581202305171a'
97100
jest.spyOn(installer, 'isInstallationNeeded').mockResolvedValue(true)
101+
jest.spyOn(cache, 'restoreCache').mockResolvedValue(undefined)
102+
jest.spyOn(cache, 'saveCache').mockResolvedValue(1)
98103
jest.spyOn(toolCache, 'find').mockReturnValue('')
99104
jest.spyOn(exec, 'exec').mockResolvedValue(0)
100105
const downloadSpy = jest.spyOn(toolCache, 'downloadTool')

0 commit comments

Comments
 (0)