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

52 lines
2.1 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-30 17:49:16 +00:00
import { TaskParameterSerializer } from './services/task-parameter-serializer';
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-30 18:47:01 +00:00
const testOutput = `${CloudRunnerState.buildParams.buildGuid}-outputfile.txt`;
2021-12-29 17:04:06 +00:00
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-30 17:49:16 +00:00
const environmentVariables = TaskParameterSerializer.readBuildEnvironmentVariables();
2021-12-29 15:43:32 +00:00
const newLinePurgedFile = file
.replace(/\s+/g, '')
.replace(new RegExp(`\\[${CloudRunnerStatics.logPrefix}\\]`, 'g'), '');
2021-12-30 17:49:16 +00:00
for (const element of environmentVariables) {
if (element.value !== undefined && typeof element.value !== 'function') {
const newLinePurgedValue = element.value.toString().replace(/\s+/g, '');
2021-12-30 19:00:01 +00:00
expect(newLinePurgedFile).toContain(`${element.name}=${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
});