generated from actions/javascript-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.test.js
44 lines (36 loc) · 1.11 KB
/
index.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
const fs = require('fs');
const core = require('@actions/core');
const path = require('path');
const run = require('./index');
const mockFs = require('mock-fs');
jest.mock('@actions/core');
describe('Create Terraform Backend File', () => {
beforeEach(() => {
mockFs({
'/github/workspace': {
'existing_directory': {}
}
});
process.env.GITHUB_WORKSPACE = '/github/workspace';
core.getInput.mockReturnValueOnce('my-bucket');
core.getInput.mockReturnValueOnce('existing_directory');
});
afterEach(() => {
mockFs.restore();
});
it('creates a .tf file', async () => {
await run();
const filePath = path.join(process.env.GITHUB_WORKSPACE, 'existing_directory', 'backend.tf');
expect(fs.existsSync(filePath)).toBe(true);
});
it('writes correct content to .tf file', async () => {
await run();
const filePath = path.join(process.env.GITHUB_WORKSPACE, 'existing_directory', 'backend.tf');
const fileContent = fs.readFileSync(filePath, 'utf-8');
expect(fileContent).toEqual(`terraform {
backend "gcs" {
bucket = "my-bucket"
}
}`);
});
});