Skip to content

Commit 3c29ba2

Browse files
committed
SIGN-7469 Add unit test
1 parent 892d8c6 commit 3c29ba2

File tree

4 files changed

+67
-1
lines changed

4 files changed

+67
-1
lines changed

actions/submit-signing-request/helper-artifact-download.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export class HelperArtifactDownload {
6767
core.info(`The signed artifact has been successfully downloaded from SignPath and extracted to ${targetDirectory}`);
6868
}
6969

70-
private resolveOrCreateDirectory(directoryPath:string): string {
70+
public resolveOrCreateDirectory(directoryPath:string): string {
7171
const workingDirectory = process.env.GITHUB_WORKSPACE as string;
7272
const absolutePath = path.isAbsolute(directoryPath) ? directoryPath :
7373
path.join(workingDirectory as string, directoryPath);
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { assert, expect } from "chai";
2+
import { HelperArtifactDownload } from "../helper-artifact-download"
3+
import * as path from 'path';
4+
import * as os from 'os';
5+
import * as uuid from 'uuid';
6+
import * as fs from 'fs'
7+
import { HelperInputOutput } from "../helper-input-output";
8+
9+
describe("Artifact path resolving tests", () => {
10+
before(() => { process.env.GITHUB_WORKSPACE = __dirname; });
11+
after(() => { process.env.GITHUB_WORKSPACE = undefined; });
12+
13+
[".", "..", "fake", "fake/path"].forEach(relativePathBase => {
14+
it("Should resolve relative paths to absolute paths", () => {
15+
const sut = new HelperArtifactDownload(new HelperInputOutput());
16+
const dirName = uuid.v4();
17+
const relativePath = path.join(relativePathBase, dirName);
18+
const expectedAbsolutePath = path.join(__dirname, relativePath);
19+
20+
let actualResolvedPath: fs.PathLike = "";
21+
try {
22+
// ACT
23+
actualResolvedPath = sut.resolveOrCreateDirectory(relativePath);
24+
25+
// ASSERT
26+
assert.equal(actualResolvedPath, expectedAbsolutePath);
27+
}
28+
finally {
29+
fs.rmSync(actualResolvedPath, { force: true, recursive: true })
30+
}
31+
})
32+
})
33+
34+
it("Should detect and recognize absolute paths", () => {
35+
const sut = new HelperArtifactDownload(new HelperInputOutput());
36+
const dirName = uuid.v4();
37+
const expectedAbsolutePath = path.join(__dirname, dirName);
38+
39+
let actualResolvedPath: fs.PathLike = "";
40+
try {
41+
// ACT
42+
actualResolvedPath = sut.resolveOrCreateDirectory(expectedAbsolutePath);
43+
44+
// ASSERT
45+
assert.equal(actualResolvedPath, expectedAbsolutePath);
46+
}
47+
finally {
48+
fs.rmSync(actualResolvedPath, { force: true, recursive: true })
49+
}
50+
})
51+
})

package-lock.json

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"@types/node": "^18.7.23",
1818
"@types/q": "^1.5.5",
1919
"@types/sinon": "^10.0.13",
20+
"@types/uuid": "^10.0.0",
2021
"@vercel/ncc": "^0.36.1",
2122
"chai": "^4.3.7",
2223
"minimist": "^1.2.6",

0 commit comments

Comments
 (0)