2020-03-24 21:26:10 +08:00
|
|
|
import { getToolchainArgs } from "../src/args";
|
|
|
|
import { morph } from "mock-env";
|
|
|
|
import { sync as tempWriteSync } from "temp-write";
|
2019-09-12 21:44:29 +08:00
|
|
|
|
2020-03-24 21:26:10 +08:00
|
|
|
describe("actions-rs/toolchain", () => {
|
|
|
|
it("Parses action input into toolchain options", () => {
|
|
|
|
const args = morph(
|
|
|
|
() => {
|
|
|
|
return getToolchainArgs("./rust-toolchain");
|
|
|
|
},
|
|
|
|
{
|
|
|
|
INPUT_TOOLCHAIN: "nightly-2019-04-20",
|
|
|
|
INPUT_DEFAULT: "false",
|
|
|
|
INPUT_OVERRIDE: "true",
|
|
|
|
}
|
|
|
|
);
|
2020-01-13 21:31:26 +08:00
|
|
|
|
2020-03-24 21:26:10 +08:00
|
|
|
expect(args.name).toBe("nightly-2019-04-20");
|
2020-01-13 21:31:26 +08:00
|
|
|
expect(args.default).toBe(false);
|
|
|
|
expect(args.override).toBe(true);
|
|
|
|
});
|
|
|
|
|
2020-03-24 21:26:10 +08:00
|
|
|
it("uses input variable if rust-toolchain file does not exist", function () {
|
|
|
|
const args = morph(
|
|
|
|
() => {
|
|
|
|
return getToolchainArgs("./rust-toolchain");
|
|
|
|
},
|
|
|
|
{
|
|
|
|
INPUT_TOOLCHAIN: "nightly",
|
|
|
|
}
|
|
|
|
);
|
2020-01-13 21:31:26 +08:00
|
|
|
|
2020-03-24 21:26:10 +08:00
|
|
|
expect(args.name).toBe("nightly");
|
2020-01-13 21:31:26 +08:00
|
|
|
});
|
|
|
|
|
2020-03-24 21:26:10 +08:00
|
|
|
it("toolchain input is required if rust-toolchain does not exist", function () {
|
|
|
|
expect(() => getToolchainArgs("./rust-toolchain")).toThrowError();
|
2020-01-13 21:31:26 +08:00
|
|
|
});
|
|
|
|
|
2020-03-24 21:26:10 +08:00
|
|
|
it("prioritizes rust-toolchain file over input variable", function () {
|
|
|
|
const rustToolchainFile = tempWriteSync("1.39.0");
|
2020-01-13 21:31:26 +08:00
|
|
|
|
2020-03-24 21:26:10 +08:00
|
|
|
const args = morph(
|
|
|
|
() => {
|
|
|
|
return getToolchainArgs(rustToolchainFile);
|
|
|
|
},
|
|
|
|
{
|
|
|
|
INPUT_TOOLCHAIN: "nightly",
|
|
|
|
}
|
|
|
|
);
|
2020-01-13 21:31:26 +08:00
|
|
|
|
2020-03-24 21:26:10 +08:00
|
|
|
expect(args.name).toBe("nightly");
|
2020-01-17 20:21:07 +08:00
|
|
|
});
|
|
|
|
|
2020-03-24 21:26:10 +08:00
|
|
|
it("uses rust-toolchain file if input does not exist", function () {
|
|
|
|
const rustToolchainFile = tempWriteSync("1.39.0");
|
2020-01-17 20:21:07 +08:00
|
|
|
|
2020-03-24 21:26:10 +08:00
|
|
|
const args = morph(() => {
|
|
|
|
return getToolchainArgs(rustToolchainFile);
|
2020-01-17 20:21:07 +08:00
|
|
|
}, {});
|
|
|
|
|
2020-03-24 21:26:10 +08:00
|
|
|
expect(args.name).toBe("1.39.0");
|
2020-01-13 21:31:26 +08:00
|
|
|
});
|
|
|
|
|
2020-03-24 21:26:10 +08:00
|
|
|
it("trims content of the override file", function () {
|
|
|
|
const rustToolchainFile = tempWriteSync("\n 1.39.0\n\n\n\n");
|
2020-01-13 21:31:26 +08:00
|
|
|
|
2020-03-24 21:26:10 +08:00
|
|
|
const args = morph(() => {
|
|
|
|
return getToolchainArgs(rustToolchainFile);
|
2020-01-17 20:21:07 +08:00
|
|
|
}, {});
|
2019-09-12 21:44:29 +08:00
|
|
|
|
2020-03-24 21:26:10 +08:00
|
|
|
expect(args.name).toBe("1.39.0");
|
2019-09-12 21:44:29 +08:00
|
|
|
});
|
|
|
|
});
|