-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmain.test.ts
116 lines (96 loc) · 3.75 KB
/
main.test.ts
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
Copyright 2019 Arduino SA
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import core = require("@actions/core");
import io = require("@actions/io");
import path = require("path");
import os = require("os");
import fs = require("fs");
import nock = require("nock");
const toolDir = path.join(__dirname, "runner", "tools");
const tempDir = path.join(__dirname, "runner", "temp");
const dataDir = path.join(__dirname, "testdata");
const IS_WINDOWS = process.platform === "win32";
process.env["RUNNER_TEMP"] = tempDir;
process.env["RUNNER_TOOL_CACHE"] = toolDir;
import * as installer from "../src/installer";
// Inputs for mock @actions/core
let inputs = {
token: process.env.GITHUB_TOKEN || "",
} as any;
describe("installer tests", () => {
beforeEach(async function () {
// Mock getInput
jest.spyOn(core, "getInput").mockImplementation((name: string) => {
return inputs[name];
});
await io.rmRF(toolDir);
await io.rmRF(tempDir);
await io.mkdirP(toolDir);
await io.mkdirP(tempDir);
});
afterAll(async () => {
try {
await io.rmRF(toolDir);
await io.rmRF(tempDir);
} catch {
console.log("Failed to remove test directories");
}
jest.restoreAllMocks();
});
it("Downloads version of arduino-lint if no matching version is installed", async () => {
const toolPath = await installer.getArduinoLint("1.0.0");
const bindir = path.join(toolDir, "arduino-lint", "1.0.0", os.arch());
expect(toolPath == path.join(bindir, "arduino-lint")).toBe(true);
expect(fs.existsSync(`${bindir}.complete`)).toBe(true);
if (IS_WINDOWS) {
expect(fs.existsSync(path.join(bindir, "arduino-lint.exe"))).toBe(true);
} else {
expect(fs.existsSync(path.join(bindir, "arduino-lint"))).toBe(true);
}
}, 20000);
describe("Gets the latest release of arduino-lint", () => {
beforeEach(() => {
jest.spyOn(core, "getInput").mockImplementation((name: string) => {
return inputs[name];
});
nock("https://api.github.com")
.get("/repos/arduino/arduino-lint/git/refs/tags")
.replyWithFile(200, path.join(dataDir, "tags.json"));
});
afterEach(() => {
nock.cleanAll();
nock.enableNetConnect();
jest.clearAllMocks();
});
it("Gets the latest version of arduino-lint 1.0.0 using 1.0 and no matching version is installed", async () => {
await installer.getArduinoLint("1.0");
const bindir = path.join(toolDir, "arduino-lint", "1.0.0", os.arch());
expect(fs.existsSync(`${bindir}.complete`)).toBe(true);
if (IS_WINDOWS) {
expect(fs.existsSync(path.join(bindir, "arduino-lint.exe"))).toBe(true);
} else {
expect(fs.existsSync(path.join(bindir, "arduino-lint"))).toBe(true);
}
}, 20000);
it("Gets latest version of the 1 major series using 1.x and no matching version is installed", async () => {
await installer.getArduinoLint("1.x");
const bindir = path.join(toolDir, "arduino-lint", "1.0.0", os.arch());
expect(fs.existsSync(`${bindir}.complete`)).toBe(true);
if (IS_WINDOWS) {
expect(fs.existsSync(path.join(bindir, "arduino-lint.exe"))).toBe(true);
} else {
expect(fs.existsSync(path.join(bindir, "arduino-lint"))).toBe(true);
}
}, 20000);
});
});