toolchain/__tests__/args.test.ts
Thomas Eizinger 568a53bc9a
Invert the priority order of the input and the rust-toolchain file
1. Not doing so would be a breaking change for users who have
a rust-toolchain file with a different version from what they
specify in the input.
2. Not doing so makes it overly complicated to install a specific
version.
Imagine you want to test your software against the version in the
rust-toolchain file and nightly as-well. Without this patch, users
will have the replace the content of the rust-toolchain file because
it is prioritized over the input.
It makes a lot more sense to prioritize the input over the file
because that one is easier changed.
2020-01-14 10:19:22 +11:00

66 lines
1.9 KiB
TypeScript

import {toolchain_args} from "../src/args";
import {morph} from "mock-env"
import {sync as tempWriteSync} from "temp-write"
describe('actions-rs/toolchain', () => {
it('Parses action input into toolchain options', async () => {
let args = morph(() => {
return toolchain_args("./rust-toolchain");
}, {
'INPUT_TOOLCHAIN': 'nightly-2019-04-20',
'INPUT_DEFAULT': 'false',
'INPUT_OVERRIDE': 'true'
});
expect(args.name).toBe('nightly-2019-04-20');
expect(args.default).toBe(false);
expect(args.override).toBe(true);
});
it('uses input variable if rust-toolchain file does not exist', function () {
let args = morph(() => {
return toolchain_args("./rust-toolchain");
}, {
'INPUT_TOOLCHAIN': 'nightly',
});
expect(args.name).toBe("nightly")
});
it('toolchain input is required if rust-toolchain does not exist', function () {
expect(() => toolchain_args("./rust-toolchain")).toThrowError()
});
it('prioritizes rust-toolchain file over input variable', function () {
let rustToolchainFile = tempWriteSync("1.39.0");
let args = morph(() => {
return toolchain_args(rustToolchainFile);
}, {
'INPUT_TOOLCHAIN': 'nightly',
});
expect(args.name).toBe("nightly")
});
it('uses rust-toolchain file if input does not exist', function () {
let rustToolchainFile = tempWriteSync("1.39.0");
let args = morph(() => {
return toolchain_args(rustToolchainFile);
}, {});
expect(args.name).toBe("1.39.0")
});
it('trims content of the override file', function () {
let rustToolchainFile = tempWriteSync("\n 1.39.0\n\n\n\n");
let args = morph(() => {
return toolchain_args(rustToolchainFile);
}, {});
expect(args.name).toBe("1.39.0")
});
});