mirror of
https://github.com/hashicorp/setup-terraform.git
synced 2026-02-04 06:18:09 +00:00
Merge 315ab497cf into ce70bcf31a
This commit is contained in:
commit
eb4f933afc
2 changed files with 43 additions and 8 deletions
|
|
@ -81,8 +81,13 @@ async function installWrapper (pathToCLI) {
|
|||
try {
|
||||
source = path.resolve([__dirname, '..', 'wrapper', 'dist', 'index.js'].join(path.sep));
|
||||
target = [pathToCLI, 'terraform'].join(path.sep);
|
||||
core.debug(`Copying ${source} to ${target}.`);
|
||||
await io.cp(source, target);
|
||||
|
||||
core.debug(`Reading wrapper from ${source} and updating shebang.`);
|
||||
const wrapperContent = (await fs.readFile(source, 'utf8')).split('\n');
|
||||
wrapperContent[0] = `#!${process.argv[0]}`;
|
||||
|
||||
core.debug(`Writing updated wrapper to ${target}.`);
|
||||
await fs.writeFile(target, wrapperContent.join('\n'), { mode: 0o755 });
|
||||
} catch (e) {
|
||||
core.error(`Unable to copy ${source} to ${target}.`);
|
||||
throw e;
|
||||
|
|
|
|||
|
|
@ -27,6 +27,9 @@ const setup = require('../lib/setup-terraform');
|
|||
// core.error = jest
|
||||
// .fn(console.error);
|
||||
|
||||
const fsReadFileImplementation = fs.readFile;
|
||||
const fsWriteFileImplementation = fs.writeFile;
|
||||
|
||||
describe('Setup Terraform', () => {
|
||||
const HOME = process.env.HOME;
|
||||
const APPDATA = process.env.APPDATA;
|
||||
|
|
@ -553,8 +556,20 @@ describe('Setup Terraform', () => {
|
|||
|
||||
const ioMv = jest.spyOn(io, 'mv')
|
||||
.mockImplementation(() => {});
|
||||
const ioCp = jest.spyOn(io, 'cp')
|
||||
.mockImplementation(() => {});
|
||||
const fsReadFile = jest.spyOn(fs, 'readFile').mockImplementation((...args) => {
|
||||
if (args[0] === wrapperPath) {
|
||||
return Promise.resolve('');
|
||||
} else {
|
||||
return fsReadFileImplementation(...args);
|
||||
}
|
||||
});
|
||||
const fsWriteFile = jest.spyOn(fs, 'writeFile').mockImplementation((...args) => {
|
||||
if (args[0] === `file${path.sep}terraform`) {
|
||||
return Promise.resolve();
|
||||
} else {
|
||||
return fsWriteFileImplementation(...args);
|
||||
}
|
||||
});
|
||||
|
||||
core.getInput = jest
|
||||
.fn()
|
||||
|
|
@ -586,7 +601,8 @@ describe('Setup Terraform', () => {
|
|||
await setup();
|
||||
|
||||
expect(ioMv).toHaveBeenCalledWith(`file${path.sep}terraform`, `file${path.sep}terraform-bin`);
|
||||
expect(ioCp).toHaveBeenCalledWith(wrapperPath, `file${path.sep}terraform`);
|
||||
expect(fsReadFile).toHaveBeenCalledWith(wrapperPath, 'utf8');
|
||||
expect(fsWriteFile).toHaveBeenCalledWith(`file${path.sep}terraform`, expect.any(String), { mode: 0o755 });
|
||||
});
|
||||
|
||||
test('installs wrapper on windows', async () => {
|
||||
|
|
@ -597,8 +613,21 @@ describe('Setup Terraform', () => {
|
|||
|
||||
const ioMv = jest.spyOn(io, 'mv')
|
||||
.mockImplementation(() => {});
|
||||
const ioCp = jest.spyOn(io, 'cp')
|
||||
.mockImplementation(() => {});
|
||||
const fsReadFileImplementation = fs.readFile;
|
||||
const fsReadFile = jest.spyOn(fs, 'readFile').mockImplementation((...args) => {
|
||||
if (args[0] === wrapperPath) {
|
||||
return Promise.resolve('');
|
||||
} else {
|
||||
return fsReadFileImplementation(...args);
|
||||
}
|
||||
});
|
||||
const fsWriteFile = jest.spyOn(fs, 'writeFile').mockImplementation((...args) => {
|
||||
if (args[0] === `file${path.sep}terraform`) {
|
||||
return Promise.resolve();
|
||||
} else {
|
||||
return fsWriteFileImplementation(...args);
|
||||
}
|
||||
});
|
||||
|
||||
core.getInput = jest
|
||||
.fn()
|
||||
|
|
@ -630,6 +659,7 @@ describe('Setup Terraform', () => {
|
|||
await setup();
|
||||
|
||||
expect(ioMv).toHaveBeenCalledWith(`file${path.sep}terraform.exe`, `file${path.sep}terraform-bin.exe`);
|
||||
expect(ioCp).toHaveBeenCalledWith(wrapperPath, `file${path.sep}terraform`);
|
||||
expect(fsReadFile).toHaveBeenCalledWith(wrapperPath, 'utf8');
|
||||
expect(fsWriteFile).toHaveBeenCalledWith(`file${path.sep}terraform`, expect.any(String), { mode: 0o755 });
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue