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

47 lines
1.7 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',
customBuildSteps: `
- 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-20 19:15:27 +00:00
if (Input.remoteBuilderIntegrationTests) {
const buildParameter = await BuildParameters.create();
buildParameter.logToFile = true;
const baseImage = new ImageTag(buildParameter);
await CloudRunner.run(buildParameter, baseImage.toString());
const file = fs.readFileSync(`${CloudRunnerState.buildGuid}-outputfile.txt`, 'utf-8').toString();
expect(file).toContain(JSON.stringify(buildParameter));
2021-12-24 03:55:22 +00:00
expect(file).toContain(`${testSecretName}=${testSecretValue}`);
2021-12-23 01:37:03 +00:00
const inputKeys = Object.getOwnPropertyNames(Input);
for (const element of inputKeys) {
if (Input[element] !== undefined && typeof Input[element] != 'function') {
2021-12-25 19:55:20 +00:00
expect(
2021-12-25 19:57:44 +00:00
file.replace(/\s+/g, '').replace(new RegExp(`\\[${CloudRunnerStatics.logPrefix}\\]`, 'g'), ''),
2021-12-25 19:55:20 +00:00
).toContain(`${element}=${Input[element].toString().replace(/\s+/g, '')}`);
2021-12-21 05:57:00 +00:00
}
}
2021-12-20 19:15:27 +00:00
}
}, 500000);
});