forked from usualdesigner/s3-artifact-upload
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.test.ts
58 lines (51 loc) · 1.68 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
import fs from "fs";
import * as core from "@actions/core";
import * as main from "../src/main";
import { Stats } from "node:fs";
let getInputMock: jest.SpyInstance;
const runMock = jest.spyOn(main, "run");
describe("Main test suite", () => {
beforeEach(() => {
jest.clearAllMocks();
jest.spyOn(fs, "statSync").mockReturnValue({ size: 42 } as Stats);
jest.spyOn(fs, "readFileSync").mockReturnValue("Hello there!");
// debugMock = jest.spyOn(core, "debug").mockImplementation();
// errorMock = jest.spyOn(core, "error").mockImplementation();
getInputMock = jest.spyOn(core, "getInput").mockImplementation();
// setFailedMock = jest.spyOn(core, "setFailed").mockImplementation();
// setOutputMock = jest.spyOn(core, "setOutput").mockImplementation();
});
afterEach(() => {
jest.restoreAllMocks();
});
it("first test", async () => {
getInputMock.mockImplementation((name: string): string => {
switch (name) {
case "aws-access-key-id":
return "testAccessKeyId";
case "aws-secret-access-key":
return "testSecretAccessKey";
case "bucket-name":
return "testBucketName";
case "region":
return "us-west-2";
case "endpoint":
return "http://localhost:9000";
case "acl":
return "public-read";
case "prefix":
return "test";
case "file":
return "file.txt";
case "meta-data":
return '{"key1": "value1", "key2": "value2"}';
case "cache-control":
return "max-age=100";
default:
return "";
}
});
await main.run();
expect(runMock).toHaveReturned();
});
});