forked from actions-rs/toolchain
-
Notifications
You must be signed in to change notification settings - Fork 1
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
06b1a58
commit c80cdd7
Showing
7 changed files
with
86 additions
and
19 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
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
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
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,79 @@ | ||
import { installToolchainCommand } from "../src/toolchain_install"; | ||
import { RustUp } from "../src/installers/rustup"; | ||
import * as semver from "semver"; | ||
import { Outputs } from "../src/output"; | ||
import * as mockedCore from "@actions/core"; | ||
|
||
jest.mock("@actions/exec", () => ({ | ||
exec: jest.fn(), | ||
})); | ||
jest.mock("@actions/core", () => ({ | ||
debug: jest.fn(), | ||
startGroup: jest.fn(), | ||
endGroup: jest.fn(), | ||
info: jest.fn(), | ||
error: jest.fn(), | ||
setOutput: jest.fn(), | ||
})); | ||
jest.mock("../src/installers/rustup", () => ({ | ||
RustUp: { | ||
getOrInstall: jest.fn(), | ||
}, | ||
})); | ||
jest.mock("../src/output", () => ({ | ||
Outputs: { | ||
outputs: jest.fn(), | ||
}, | ||
})); | ||
|
||
describe("Tests of toolchain command", () => { | ||
const originalEnv = process.env; | ||
|
||
afterEach(() => { | ||
process.env = originalEnv; | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
test("Outputs", async () => { | ||
process.env.INPUT_PROFILE = "minim"; | ||
|
||
const obj = { | ||
supportProfiles: jest.fn(async (): Promise<boolean> => { | ||
return Promise.resolve(true); | ||
}), | ||
supportComponents: jest.fn(async (): Promise<boolean> => { | ||
return Promise.resolve(true); | ||
}), | ||
setProfile: jest.fn(), | ||
installToolchain: jest.fn(async (): Promise<number> => { | ||
return Promise.resolve(0); | ||
}), | ||
version: jest.fn((): Promise<semver.SemVer> => { | ||
return Promise.resolve(semver.parse("2.2.2") as semver.SemVer); | ||
}), | ||
selfUpdate: jest.fn(), | ||
activeToolchain: jest.fn().mockReturnValue("active toolchain"), | ||
}; | ||
(RustUp.getOrInstall as jest.Mock).mockImplementation(async () => { | ||
return Promise.resolve(obj); | ||
}); | ||
(Outputs.outputs as jest.Mock).mockReturnValue( | ||
Promise.resolve([ | ||
{ | ||
name: "rustc", | ||
value: "version", | ||
}, | ||
]), | ||
); | ||
|
||
installToolchainCommand | ||
.hook("postAction", () => { | ||
expect(mockedCore.setOutput).toHaveBeenCalledTimes(1); | ||
expect(mockedCore.setOutput).toHaveBeenCalledWith( | ||
"rustc", | ||
"version", | ||
); | ||
}) | ||
.parse([]); | ||
}); | ||
}); |