Files
setup-go/__tests__/cache-restore.test.ts
Kai 0948bf67a8
Validate Microsoft build of Go / Microsoft build of Go 1.24 on macos-latest (push) Canceled after 0s
Validate Microsoft build of Go / Microsoft build of Go 1.24 on windows-latest (push) Canceled after 0s
Validate Microsoft build of Go / Microsoft build of Go 1.25 on macos-latest (push) Canceled after 0s
Validate Microsoft build of Go / Microsoft build of Go 1.25 on ubuntu-latest (push) Canceled after 0s
Validate Microsoft build of Go / Microsoft build of Go 1.25 on windows-latest (push) Canceled after 0s
Validate Microsoft build of Go / Microsoft build of Go via env var on macos-latest (push) Canceled after 0s
Validate Microsoft build of Go / Microsoft build of Go via env var on ubuntu-latest (push) Canceled after 0s
Validate Microsoft build of Go / Microsoft build of Go via env var on windows-latest (push) Canceled after 0s
Validate Microsoft build of Go / Microsoft build of Go arch arm64 on macos-latest (push) Canceled after 0s
Validate Microsoft build of Go / Microsoft build of Go arch x64 on macos-latest (push) Canceled after 0s
Validate Microsoft build of Go / Microsoft build of Go arch x64 on ubuntu-latest (push) Canceled after 0s
Validate Microsoft build of Go / Microsoft build of Go with caching on macos-latest (push) Canceled after 0s
Validate Microsoft build of Go / Microsoft build of Go with caching on ubuntu-latest (push) Canceled after 0s
Validate Microsoft build of Go / Microsoft build of Go with caching on windows-latest (push) Canceled after 0s
Validate Microsoft build of Go / Microsoft build of Go 1.24 on ubuntu-latest (push) Canceled after 3s
Validate 'setup-go' / stable (macos-15-intel) (push) Canceled after 0s
Validate 'setup-go' / stable (macos-latest) (push) Canceled after 0s
Validate 'setup-go' / stable (windows-latest) (push) Canceled after 0s
Validate 'setup-go' / oldstable (macos-15-intel) (push) Canceled after 0s
Validate 'setup-go' / oldstable (macos-latest) (push) Canceled after 0s
Validate 'setup-go' / oldstable (ubuntu-latest) (push) Canceled after 0s
Validate 'setup-go' / oldstable (windows-latest) (push) Canceled after 0s
Validate 'setup-go' / go-env-outputs (macos-latest) (push) Canceled after 0s
Validate 'setup-go' / go-env-outputs (ubuntu-latest) (push) Canceled after 0s
Validate 'setup-go' / go-env-outputs (windows-latest) (push) Canceled after 0s
Validate 'setup-go' / aliases-arch (x32, ubuntu-latest, oldstable) (push) Canceled after 0s
Validate 'setup-go' / aliases-arch (x32, ubuntu-latest, stable) (push) Canceled after 0s
Validate 'setup-go' / check-latest (1.21, macos-15-intel) (push) Canceled after 0s
Validate 'setup-go' / aliases-arch (x32, windows-latest, oldstable) (push) Canceled after 0s
Validate 'setup-go' / aliases-arch (x32, windows-latest, stable) (push) Canceled after 0s
Validate 'setup-go' / aliases-arch (x64, macos-15-intel, oldstable) (push) Canceled after 0s
Validate 'setup-go' / aliases-arch (x64, macos-15-intel, stable) (push) Canceled after 0s
Validate 'setup-go' / aliases-arch (x64, macos-latest, oldstable) (push) Canceled after 0s
Validate 'setup-go' / aliases-arch (x64, macos-latest, stable) (push) Canceled after 0s
Validate 'setup-go' / aliases-arch (x64, ubuntu-latest, oldstable) (push) Canceled after 0s
Validate 'setup-go' / aliases-arch (x64, ubuntu-latest, stable) (push) Canceled after 0s
Validate 'setup-go' / aliases-arch (x64, windows-latest, oldstable) (push) Canceled after 0s
Validate 'setup-go' / aliases-arch (x64, windows-latest, stable) (push) Canceled after 0s
Validate 'setup-go' / Setup local-cache version (1.20.14, windows-latest) (push) Canceled after 0s
Validate 'setup-go' / Setup local-cache version (1.21.13, macos-15-intel) (push) Canceled after 0s
Validate 'setup-go' / Setup local-cache version (1.21.13, macos-latest) (push) Canceled after 0s
Validate 'setup-go' / Setup local-cache version (1.21.13, ubuntu-latest) (push) Canceled after 0s
Validate 'setup-go' / Setup local-cache version (1.21.13, windows-latest) (push) Canceled after 0s
Validate 'setup-go' / Setup local-cache version (1.22.8, macos-15-intel) (push) Canceled after 0s
Validate 'setup-go' / Setup local-cache version (1.22.8, macos-latest) (push) Canceled after 0s
Validate 'setup-go' / Setup local-cache version (1.22.8, ubuntu-latest) (push) Canceled after 0s
Validate 'setup-go' / Setup local-cache version (1.22.8, windows-latest) (push) Canceled after 0s
Validate 'setup-go' / Setup local-cache version (1.23.2, macos-15-intel) (push) Canceled after 0s
Validate 'setup-go' / Setup local-cache version (1.23.2, macos-latest) (push) Canceled after 0s
Validate 'setup-go' / Setup local-cache version (1.23.2, ubuntu-latest) (push) Canceled after 0s
Validate 'setup-go' / check-latest (1.20, macos-15-intel) (push) Canceled after 0s
Validate 'setup-go' / check-latest (1.20, macos-latest) (push) Canceled after 0s
Validate 'setup-go' / check-latest (1.20, ubuntu-latest) (push) Canceled after 0s
Validate 'setup-go' / check-latest (1.20, windows-latest) (push) Canceled after 0s
Validate 'setup-go' / check-latest (1.21, macos-latest) (push) Canceled after 0s
Validate 'setup-go' / check-latest (1.21, ubuntu-latest) (push) Canceled after 0s
Validate 'setup-go' / check-latest (1.21, windows-latest) (push) Canceled after 0s
Validate 'setup-go' / check-latest (1.22, macos-15-intel) (push) Canceled after 0s
Validate 'setup-go' / stable (ubuntu-latest) (push) Canceled after 3s
Validate 'setup-go' / check-latest (1.22, macos-latest) (push) Canceled after 0s
Validate 'setup-go' / check-latest (1.22, ubuntu-latest) (push) Canceled after 0s
Validate 'setup-go' / check-latest (1.22, windows-latest) (push) Canceled after 0s
Validate 'setup-go' / check-latest (1.23, macos-15-intel) (push) Canceled after 0s
Validate 'setup-go' / check-latest (1.23, macos-latest) (push) Canceled after 0s
Validate 'setup-go' / check-latest (1.23, ubuntu-latest) (push) Canceled after 0s
Validate 'setup-go' / check-latest (1.23, windows-latest) (push) Canceled after 0s
Validate 'setup-go' / go-version-file (macos-15-intel) (push) Canceled after 0s
Validate 'setup-go' / go-version-file (macos-latest) (push) Canceled after 0s
Validate 'setup-go' / go-version-file (ubuntu-latest) (push) Canceled after 0s
Validate 'setup-go' / go-version-file (windows-latest) (push) Canceled after 0s
Validate 'setup-go' / go-version-file-with-gowork (macos-15-intel) (push) Canceled after 0s
Validate 'setup-go' / go-version-file-with-gowork (macos-latest) (push) Canceled after 0s
Validate 'setup-go' / go-version-file-with-gowork (ubuntu-latest) (push) Canceled after 0s
Validate 'setup-go' / go-version-file-with-gowork (windows-latest) (push) Canceled after 0s
Validate 'setup-go' / go-version-file-with-tool-versions (macos-15-intel) (push) Canceled after 0s
Validate 'setup-go' / go-version-file-with-tool-versions (macos-latest) (push) Canceled after 0s
Validate 'setup-go' / go-version-file-with-tool-versions (ubuntu-latest) (push) Canceled after 0s
Validate 'setup-go' / go-version-file-with-tool-versions (windows-latest) (push) Canceled after 0s
Validate 'setup-go' / go-version-file-with-go-version (macos-15-intel) (push) Canceled after 0s
Validate 'setup-go' / go-version-file-with-go-version (macos-latest) (push) Canceled after 0s
Validate 'setup-go' / go-version-file-with-go-version (ubuntu-latest) (push) Canceled after 0s
Validate 'setup-go' / go-version-file-with-go-version (windows-latest) (push) Canceled after 0s
Validate 'setup-go' / setup-versions-from-manifest (1.20.14, macos-15-intel) (push) Canceled after 0s
Validate 'setup-go' / setup-versions-from-manifest (1.20.14, windows-latest) (push) Canceled after 0s
Validate 'setup-go' / setup-versions-from-manifest (1.21.10, ubuntu-latest) (push) Canceled after 0s
Validate 'setup-go' / setup-versions-from-manifest (1.21.10, windows-latest) (push) Canceled after 0s
Validate 'setup-go' / setup-versions-from-manifest (1.22.8, macos-latest) (push) Canceled after 0s
Validate 'setup-go' / setup-versions-from-manifest (1.22.8, ubuntu-latest) (push) Canceled after 0s
Validate 'setup-go' / setup-versions-from-manifest (1.22.8, windows-latest) (push) Canceled after 0s
Validate 'setup-go' / setup-versions-from-manifest (1.23.2, macos-latest) (push) Canceled after 0s
Validate 'setup-go' / setup-versions-from-dist (1.11.12, ubuntu-latest) (push) Canceled after 0s
Validate 'setup-go' / setup-versions-from-dist (1.11.12, windows-latest) (push) Canceled after 0s
Validate 'setup-go' / architecture (arm64, 1.20.14, macos-latest) (push) Canceled after 0s
Validate 'setup-go' / architecture (arm64, 1.22, macos-latest) (push) Canceled after 0s
Validate 'setup-go' / architecture (arm64, 1.23, macos-latest) (push) Canceled after 0s
Validate 'setup-go' / architecture (x64, 1.20.14, ubuntu-latest) (push) Canceled after 0s
Validate 'setup-go' / architecture (x64, 1.20.14, windows-latest) (push) Canceled after 0s
Validate 'setup-go' / architecture (x64, 1.21, macos-15-intel) (push) Canceled after 0s
Validate 'setup-go' / architecture (x64, 1.21, ubuntu-latest) (push) Canceled after 0s
Validate 'setup-go' / architecture (x64, 1.21, windows-latest) (push) Canceled after 0s
Validate 'setup-go' / setup-versions-from-manifest (1.20.14, macos-latest) (push) Canceled after 0s
Validate 'setup-go' / setup-versions-from-manifest (1.20.14, ubuntu-latest) (push) Canceled after 0s
Validate 'setup-go' / setup-versions-from-manifest (1.21.10, macos-15-intel) (push) Canceled after 0s
Validate 'setup-go' / setup-versions-from-manifest (1.21.10, macos-latest) (push) Canceled after 0s
Validate 'setup-go' / setup-versions-from-manifest (1.22.8, macos-15-intel) (push) Canceled after 0s
Validate 'setup-go' / setup-versions-from-manifest (1.23.2, macos-15-intel) (push) Canceled after 0s
Validate 'setup-go' / setup-versions-from-manifest (1.23.2, ubuntu-latest) (push) Canceled after 0s
Validate 'setup-go' / setup-versions-from-manifest (1.23.2, windows-latest) (push) Canceled after 0s
Validate 'setup-go' / setup-versions-from-dist (1.11.12, macos-15-intel) (push) Canceled after 0s
Validate 'setup-go' / architecture (arm64, 1.21, macos-latest) (push) Canceled after 0s
Validate 'setup-go' / architecture (x64, 1.20.14, macos-15-intel) (push) Canceled after 0s
Validate 'setup-go' / architecture (x64, 1.22, macos-15-intel) (push) Canceled after 0s
Validate 'setup-go' / architecture (x64, 1.22, ubuntu-latest) (push) Canceled after 0s
Validate 'setup-go' / architecture (x64, 1.23, macos-15-intel) (push) Canceled after 0s
Validate 'setup-go' / architecture (x64, 1.22, windows-latest) (push) Canceled after 0s
Validate 'setup-go' / architecture (x64, 1.23, ubuntu-latest) (push) Canceled after 0s
Validate 'setup-go' / architecture (x64, 1.23, windows-latest) (push) Canceled after 0s
Validate Windows installation / Validate if symlink is created (false, 1.20.1) (push) Canceled after 0s
Validate Windows installation / Validate if symlink is created (true, 1.20.1) (push) Canceled after 0s
Validate Windows installation / Find default go version (push) Canceled after 0s
Validate Windows installation / Validate if symlink is not created for default go (false) (push) Canceled after 0s
Validate Windows installation / Validate if symlink is not created for default go (true) (push) Canceled after 0s
Validate Windows installation / Validate if hostedtoolcache works as expected (false, 1.20.1) (push) Canceled after 0s
first commit
2026-10-30 14:19:38 +08:00

154 lines
4.6 KiB
TypeScript

import {jest, describe, it, expect, beforeEach, afterEach} from '@jest/globals';
import fs from 'fs';
jest.unstable_mockModule('@actions/cache', () => ({
saveCache: jest.fn(),
restoreCache: jest.fn(),
isFeatureAvailable: jest.fn()
}));
jest.unstable_mockModule('@actions/glob', () => ({
create: jest.fn(),
hashFiles: jest.fn()
}));
jest.unstable_mockModule('@actions/core', () => ({
info: jest.fn(),
warning: jest.fn(),
debug: jest.fn(),
error: jest.fn(),
notice: jest.fn(),
setFailed: jest.fn(),
setOutput: jest.fn(),
getInput: jest.fn(),
getBooleanInput: jest.fn(),
getMultilineInput: jest.fn(),
addPath: jest.fn(),
exportVariable: jest.fn(),
saveState: jest.fn(),
getState: jest.fn(),
setSecret: jest.fn(),
isDebug: jest.fn(() => false),
startGroup: jest.fn(),
endGroup: jest.fn(),
group: jest.fn((_name: string, fn: () => Promise<unknown>) => fn()),
toPlatformPath: jest.fn((p: string) => p),
toWin32Path: jest.fn((p: string) => p),
toPosixPath: jest.fn((p: string) => p)
}));
// Import real cache-utils (with mocked @actions) before mocking it
const realCacheUtils = await import('../src/cache-utils.js');
jest.unstable_mockModule('../src/cache-utils.js', () => ({
...realCacheUtils,
getCacheDirectoryPath: jest.fn()
}));
const cache = await import('@actions/cache');
const core = await import('@actions/core');
const glob = await import('@actions/glob');
const cacheRestore = await import('../src/cache-restore.js');
const cacheUtils = await import('../src/cache-utils.js');
import type {PackageManagerInfo} from '../src/package-managers.js';
describe('restoreCache', () => {
let hashFilesSpy: jest.Mock<typeof glob.hashFiles>;
let getCacheDirectoryPathSpy: jest.Mock<
typeof cacheUtils.getCacheDirectoryPath
>;
let restoreCacheSpy: jest.Mock<typeof cache.restoreCache>;
let infoSpy: jest.Mock<typeof core.info>;
let setOutputSpy: jest.Mock<typeof core.setOutput>;
const versionSpec = '1.13.1';
const packageManager = 'default';
const cacheDependencyPath = 'path';
let originalWorkspace: string | undefined;
beforeEach(() => {
originalWorkspace = process.env.GITHUB_WORKSPACE;
process.env.GITHUB_WORKSPACE = '/test/workspace';
//Arrange
hashFilesSpy = glob.hashFiles as jest.Mock<typeof glob.hashFiles>;
getCacheDirectoryPathSpy = cacheUtils.getCacheDirectoryPath as jest.Mock<
typeof cacheUtils.getCacheDirectoryPath
>;
restoreCacheSpy = cache.restoreCache as jest.Mock<
typeof cache.restoreCache
>;
infoSpy = core.info as jest.Mock<typeof core.info>;
setOutputSpy = core.setOutput as jest.Mock<typeof core.setOutput>;
getCacheDirectoryPathSpy.mockImplementation(
(PackageManager: PackageManagerInfo) => {
return Promise.resolve([
'cache_directory_path',
'cache_directory_path'
]);
}
);
});
afterEach(() => {
process.env.GITHUB_WORKSPACE = originalWorkspace;
jest.restoreAllMocks();
});
it('should throw if dependency file path is not valid', async () => {
// Arrange
hashFilesSpy.mockImplementation(() => Promise.resolve(''));
// Act + Assert
await expect(
cacheRestore.restoreCache(
versionSpec,
packageManager,
cacheDependencyPath
)
).rejects.toThrow(
'Some specified paths were not resolved, unable to cache dependencies.'
);
});
it('should inform if cache hit is not occurred', async () => {
// Arrange
hashFilesSpy.mockImplementation(() => Promise.resolve('file_hash'));
restoreCacheSpy.mockImplementation(() => Promise.resolve(''));
// Act + Assert
await cacheRestore.restoreCache(
versionSpec,
packageManager,
cacheDependencyPath
);
expect(infoSpy).toHaveBeenCalledWith('Cache is not found');
});
it('should set output if cache hit is occurred', async () => {
// Arrange
hashFilesSpy.mockImplementation(() => Promise.resolve('file_hash'));
restoreCacheSpy.mockImplementation(() => Promise.resolve('cache_key'));
// Act + Assert
await cacheRestore.restoreCache(
versionSpec,
packageManager,
cacheDependencyPath
);
expect(setOutputSpy).toHaveBeenCalledWith('cache-hit', true);
});
it('should throw if dependency file is not found in workspace', async () => {
jest.spyOn(fs, 'readdirSync').mockReturnValue(['main.go'] as any);
await expect(
cacheRestore.restoreCache(
versionSpec,
packageManager
// No cacheDependencyPath
)
).rejects.toThrow(
'Dependencies file is not found in /test/workspace. Supported file pattern: go.mod'
);
});
});