forked from actions-rs/toolchain
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
46f8461
commit 06b1a58
Showing
1 changed file
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import { Outputs } from "../src/output"; | ||
import * as mockedExecUtils from "../src/utils/exec"; | ||
|
||
jest.mock("@actions/core", () => ({ | ||
info: jest.fn(), | ||
debug: jest.fn(), | ||
})); | ||
describe("Outputs tests", () => { | ||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
test("Rustc version", async () => { | ||
for (const stdout of [ | ||
"rustc 1.75.0-nightly (aa1a71e9e 2023-10-26)", | ||
"rustc 1.75.0 (aa1a71e9e 2023-10-26)", | ||
]) { | ||
jest.spyOn(mockedExecUtils, "execStdout").mockReturnValue( | ||
Promise.resolve(stdout), | ||
); | ||
const output = await Outputs.rustc(); | ||
expect(output.value).toBe(stdout.split(" ")[1]); | ||
} | ||
}); | ||
|
||
test("Rustc hash", async () => { | ||
for (const stdout of [ | ||
"rustc 1.75.0-nightly (aa1a71e9e 2023-10-26)", | ||
"rustc 1.75.0 (aa1a71e9e 2023-10-26)", | ||
]) { | ||
jest.spyOn(mockedExecUtils, "execStdout").mockReturnValue( | ||
Promise.resolve(stdout), | ||
); | ||
const output = await Outputs.rustcHash(); | ||
expect(output.value).toBe( | ||
stdout.split(" ")[2].split(" ")[0].substring(1), | ||
); | ||
} | ||
}); | ||
|
||
test("Cargo version", async () => { | ||
for (const stdout of [ | ||
"cargo 1.75.0-nightly (df3509237 2023-10-24)", | ||
"cargo 1.75.0 (df3509237 2023-10-24)", | ||
]) { | ||
jest.spyOn(mockedExecUtils, "execStdout").mockReturnValue( | ||
Promise.resolve(stdout), | ||
); | ||
const output = await Outputs.cargo(); | ||
expect(output.value).toBe(stdout.split(" ")[1]); | ||
} | ||
}); | ||
|
||
test("Rustup version", async () => { | ||
for (const stdout of [ | ||
"rustup 1.26.0 (5af9b9484 2023-04-05)\n" + | ||
"info: This is the version for the rustup toolchain manager, not the rustc compiler.\n" + | ||
"info: The currently active `rustc` version is `rustc 1.75.0-nightly (aa1a71e9e 2023-10-26)`", | ||
]) { | ||
jest.spyOn(mockedExecUtils, "execStdout").mockReturnValue( | ||
Promise.resolve(stdout), | ||
); | ||
const output = await Outputs.rustUp(); | ||
expect(output.value).toBe(stdout.split(" ")[1]); | ||
} | ||
}); | ||
|
||
test("All", async () => { | ||
jest.spyOn(Outputs, "rustc").mockReturnValue( | ||
Promise.resolve({ | ||
name: "rustc", | ||
value: "rustc", | ||
}), | ||
); | ||
jest.spyOn(Outputs, "rustcHash").mockReturnValue( | ||
Promise.resolve({ | ||
name: "rustc_hash", | ||
value: "rustcHash", | ||
}), | ||
); | ||
jest.spyOn(Outputs, "cargo").mockReturnValue( | ||
Promise.resolve({ | ||
name: "cargo", | ||
value: "cargo", | ||
}), | ||
); | ||
jest.spyOn(Outputs, "rustUp").mockReturnValue( | ||
Promise.resolve({ | ||
name: "rustup", | ||
value: "rustup", | ||
}), | ||
); | ||
|
||
expect( | ||
(await new Outputs().outputs()) | ||
.map((output) => { | ||
return output.value; | ||
}) | ||
.toString(), | ||
).toBe(["rustc", "rustcHash", "cargo", "rustup"].toString()); | ||
}); | ||
}); |