unity-builder/src/model/cloud-runner/cloud-runner.test.ts

51 lines
1.9 KiB
TypeScript
Raw Normal View History

2021-12-19 23:46:04 +00:00
import { BuildParameters, ImageTag } from '..';
import CloudRunner from './cloud-runner';
import Input from '../input';
2021-12-20 19:31:09 +00:00
import fs from 'fs';
import { CloudRunnerState } from './state/cloud-runner-state';
2021-12-25 19:57:44 +00:00
import { CloudRunnerStatics } from './cloud-runner-statics';
2021-12-19 23:46:04 +00:00
2021-12-20 00:22:47 +00:00
describe('Cloud Runner', () => {
it('responds', () => {});
});
2021-12-20 19:15:27 +00:00
describe('Cloud Runner', () => {
2021-12-24 03:55:22 +00:00
const testSecretName = 'testSecretName';
const testSecretValue = 'testSecretValue';
2021-12-20 00:04:46 +00:00
Input.cliOptions = {
versioning: 'None',
projectPath: 'test-project',
customJob: `
2021-12-20 00:04:46 +00:00
- name: 'step 1'
image: 'alpine'
commands: ['printenv']
secrets:
2021-12-24 03:55:22 +00:00
- name: '${testSecretName}'
value: '${testSecretValue}'
2021-12-20 00:04:46 +00:00
`,
};
Input.githubEnabled = false;
it('All build parameters sent to cloud runner as env vars', async () => {
2021-12-25 20:05:17 +00:00
if (Input.cloudRunnerTests) {
2021-12-20 19:15:27 +00:00
const buildParameter = await BuildParameters.create();
buildParameter.logToFile = true;
const baseImage = new ImageTag(buildParameter);
await CloudRunner.run(buildParameter, baseImage.toString());
2021-12-29 17:04:06 +00:00
const testOutput = `${CloudRunnerState.buildGuid}-outputfile.txt`;
expect(fs.existsSync(testOutput)).toBeTruthy();
const file = fs.readFileSync(testOutput, 'utf-8').toString();
expect(file).toContain(JSON.stringify(buildParameter));
2021-12-30 16:04:12 +00:00
expect(file).toContain(`${Input.ToEnvVarFormat(testSecretName)}=${testSecretValue}`);
2021-12-23 01:37:03 +00:00
const inputKeys = Object.getOwnPropertyNames(Input);
2021-12-29 15:43:32 +00:00
const newLinePurgedFile = file
.replace(/\s+/g, '')
.replace(new RegExp(`\\[${CloudRunnerStatics.logPrefix}\\]`, 'g'), '');
2021-12-23 01:37:03 +00:00
for (const element of inputKeys) {
if (Input[element] !== undefined && typeof Input[element] !== 'function') {
2021-12-29 15:43:32 +00:00
const newLinePurgedValue = Input[element].toString().replace(/\s+/g, '');
2021-12-30 16:04:12 +00:00
expect(newLinePurgedFile).toContain(`${Input.ToEnvVarFormat(element)}=${newLinePurgedValue}`);
2021-12-21 05:57:00 +00:00
}
}
2021-12-20 19:15:27 +00:00
}
2021-12-30 03:34:12 +00:00
}, 1000000);
2021-12-20 19:15:27 +00:00
});