-
Notifications
You must be signed in to change notification settings - Fork 71
Expand file tree
/
Copy pathSetup.test.ts
More file actions
65 lines (54 loc) 路 2.5 KB
/
Copy pathSetup.test.ts
File metadata and controls
65 lines (54 loc) 路 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import * as core from "@actions/core";
import { HttpClient } from "@actions/http-client";
import * as tc from "@actions/tool-cache";
import Setup, { sqlcmdDownloadUrl, sqlcmdFallbackVersion, sqlcmdToolName } from "../src/Setup";
jest.mock('@actions/core');
describe('Setup.ts tests', () => {
afterEach(() => {
jest.restoreAllMocks();
})
it('sets up sqlcmd correctly', async() => {
const extractVersionSpy = jest.spyOn(Setup, 'extractVersionFromLatestRelease').mockResolvedValue('1.1.1');
const cacheLookupSpy = jest.spyOn(tc, 'find').mockReturnValue('');
const downloadToolSpy = jest.spyOn(tc, 'downloadTool').mockResolvedValue('');
const extractTarSpy = jest.spyOn(tc, 'extractTar').mockResolvedValue('');
const extractZipSpy = jest.spyOn(tc, 'extractZip').mockResolvedValue('');
const addPathSpy = jest.spyOn(core, 'addPath');
const cacheDirSpy = jest.spyOn(tc, 'cacheDir').mockResolvedValue('');
await Setup.setupSqlcmd();
expect(extractVersionSpy).toHaveBeenCalled();
expect(cacheLookupSpy).toHaveBeenCalled();
expect(downloadToolSpy).toHaveBeenCalled();
if (process.platform === 'win32') {
expect(extractZipSpy).toHaveBeenCalled();
}
else if (process.platform === 'linux') {
expect(extractTarSpy).toHaveBeenCalled();
}
expect(addPathSpy).toHaveBeenCalled();
expect(cacheDirSpy).toHaveBeenCalled();
});
it('gets the version number from the latest release', async() => {
const headSpy = jest.spyOn(HttpClient.prototype, 'head').mockResolvedValue({
message: {
headers: {
location: 'https://github.com/microsoft/go-sqlcmd/releases/tag/v0.100.100'
}
}
} as any);
const version = await Setup.extractVersionFromLatestRelease(sqlcmdDownloadUrl);
expect(headSpy).toHaveBeenCalled();
expect(version).toBe('0.100.100');
});
it('uses fallback version when latest version cannot be determined', async() => {
const headSpy = jest.spyOn(HttpClient.prototype, 'head').mockResolvedValue({
message: {
headers: {}
}
} as any);
const cacheLookupSpy = jest.spyOn(tc, 'find').mockReturnValue('fake_path');
await Setup.setupSqlcmd();
expect(headSpy).toHaveBeenCalled();
expect(cacheLookupSpy).toHaveBeenCalledWith(sqlcmdToolName, sqlcmdFallbackVersion);
});
})