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

50 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-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-30 21:48:18 +00:00
import UnityVersioning from '../unity-versioning';
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',
2021-12-30 21:48:18 +00:00
unityVersion: UnityVersioning.read('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();
const baseImage = new ImageTag(buildParameter);
2021-12-30 20:25:28 +00:00
const file = await CloudRunner.run(buildParameter, baseImage.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') {
2021-12-30 20:25:28 +00:00
if (typeof element.value === `string`) {
2021-12-30 21:11:58 +00:00
element.value = element.value.replace(/\s+/g, '');
2021-12-30 20:25:28 +00:00
}
expect(newLinePurgedFile).toContain(`${element.name}=${element.value}`);
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
});