2019-07-25 06:17:19 +00:00
|
|
|
import fs from 'fs';
|
2020-02-05 00:14:31 +00:00
|
|
|
import { extractPackageFile } from './extract';
|
2019-07-01 13:43:01 +00:00
|
|
|
|
|
|
|
const yamlFile = fs.readFileSync(
|
2020-06-29 13:11:56 +00:00
|
|
|
'lib/manager/gitlabci-include/__fixtures__/gitlab-ci.1.yaml',
|
|
|
|
'utf8'
|
|
|
|
);
|
|
|
|
const yamlLocal = fs.readFileSync(
|
|
|
|
'lib/manager/gitlabci-include/__fixtures__/gitlab-ci.2.yaml',
|
|
|
|
'utf8'
|
|
|
|
);
|
|
|
|
|
|
|
|
const yamlLocalBlock = fs.readFileSync(
|
|
|
|
'lib/manager/gitlabci-include/__fixtures__/gitlab-ci.3.yaml',
|
2019-07-01 13:43:01 +00:00
|
|
|
'utf8'
|
|
|
|
);
|
|
|
|
|
|
|
|
describe('lib/manager/gitlabci-include/extract', () => {
|
|
|
|
describe('extractPackageFile()', () => {
|
2020-06-29 13:11:56 +00:00
|
|
|
it('returns null for empty', async () => {
|
2019-07-01 13:43:01 +00:00
|
|
|
expect(
|
2020-06-29 13:11:56 +00:00
|
|
|
await extractPackageFile('nothing here', '.gitlab-ci.yml', {})
|
2019-07-01 13:43:01 +00:00
|
|
|
).toBeNull();
|
|
|
|
});
|
2020-06-29 13:11:56 +00:00
|
|
|
it('extracts multiple include blocks', async () => {
|
|
|
|
const res = await extractPackageFile(yamlFile, '.gitlab-ci.yml', {});
|
2019-07-01 13:43:01 +00:00
|
|
|
expect(res.deps).toMatchSnapshot();
|
|
|
|
expect(res.deps).toHaveLength(3);
|
|
|
|
});
|
2020-06-29 13:11:56 +00:00
|
|
|
it('extracts local include block', async () => {
|
|
|
|
const res = await extractPackageFile(yamlLocal, '.gitlab-ci.yml', {});
|
|
|
|
expect(res.deps).toMatchSnapshot();
|
|
|
|
expect(res.deps).toHaveLength(1);
|
|
|
|
});
|
|
|
|
it('extracts multiple local include blocks', async () => {
|
|
|
|
const res = await extractPackageFile(
|
|
|
|
yamlLocalBlock,
|
|
|
|
'.gitlab-ci.yml',
|
|
|
|
{}
|
|
|
|
);
|
|
|
|
expect(res.deps).toMatchSnapshot();
|
|
|
|
expect(res.deps).toHaveLength(2);
|
|
|
|
});
|
|
|
|
it('normalizes configured endpoints', async () => {
|
2019-09-30 04:19:08 +00:00
|
|
|
const endpoints = [
|
|
|
|
'http://gitlab.test/api/v4',
|
|
|
|
'http://gitlab.test/api/v4/',
|
|
|
|
];
|
2020-06-29 13:11:56 +00:00
|
|
|
|
|
|
|
for (const endpoint of endpoints) {
|
|
|
|
const res = await extractPackageFile(yamlFile, '.gitlab-ci.yml', {
|
2019-09-30 04:19:08 +00:00
|
|
|
endpoint,
|
|
|
|
});
|
|
|
|
expect(res.deps[0].registryUrls[0]).toEqual('http://gitlab.test');
|
2020-06-29 13:11:56 +00:00
|
|
|
}
|
2019-09-30 04:19:08 +00:00
|
|
|
});
|
2019-07-01 13:43:01 +00:00
|
|
|
});
|
|
|
|
});
|