2019-07-25 06:17:19 +00:00
|
|
|
import { readFileSync } from 'fs';
|
2020-02-05 00:14:31 +00:00
|
|
|
import { updateDependency } from './update';
|
2018-07-22 04:33:11 +00:00
|
|
|
|
2019-07-25 06:17:19 +00:00
|
|
|
const yamlFile = readFileSync(
|
2020-02-05 00:14:31 +00:00
|
|
|
'lib/manager/gitlabci/__fixtures__/gitlab-ci.yaml',
|
2018-07-22 04:33:11 +00:00
|
|
|
'utf8'
|
|
|
|
);
|
|
|
|
|
|
|
|
describe('manager/gitlabci/update', () => {
|
|
|
|
describe('updateDependency', () => {
|
|
|
|
it('replaces existing value', () => {
|
|
|
|
const upgrade = {
|
2019-07-22 06:57:28 +00:00
|
|
|
managerData: { lineNumber: 36 },
|
2018-07-22 04:33:11 +00:00
|
|
|
depType: 'image',
|
|
|
|
depName: 'hadolint/hadolint',
|
|
|
|
newValue: '7.0.0',
|
|
|
|
newDigest: 'sha256:abcdefghijklmnop',
|
|
|
|
};
|
2020-02-06 13:01:21 +00:00
|
|
|
const res = updateDependency({ fileContent: yamlFile, upgrade });
|
2018-07-22 04:33:11 +00:00
|
|
|
expect(res).not.toEqual(yamlFile);
|
|
|
|
expect(res.includes(upgrade.newDigest)).toBe(true);
|
|
|
|
});
|
|
|
|
it('returns same', () => {
|
|
|
|
const upgrade = {
|
|
|
|
depType: 'image',
|
2019-07-22 06:57:28 +00:00
|
|
|
managerData: { lineNumber: 36 },
|
2018-07-22 04:33:11 +00:00
|
|
|
depName: 'hadolint/hadolint',
|
|
|
|
newValue: 'latest',
|
|
|
|
};
|
2020-02-06 13:01:21 +00:00
|
|
|
const res = updateDependency({ fileContent: yamlFile, upgrade });
|
2018-07-22 04:33:11 +00:00
|
|
|
expect(res).toEqual(yamlFile);
|
|
|
|
});
|
|
|
|
it('returns null if mismatch', () => {
|
|
|
|
const upgrade = {
|
2019-07-22 06:57:28 +00:00
|
|
|
managerData: { lineNumber: 17 },
|
2018-07-22 04:33:11 +00:00
|
|
|
depType: 'image',
|
|
|
|
depName: 'postgres',
|
|
|
|
newValue: '9.6.8',
|
|
|
|
newDigest: 'sha256:abcdefghijklmnop',
|
|
|
|
};
|
2020-02-06 13:01:21 +00:00
|
|
|
const res = updateDependency({ fileContent: yamlFile, upgrade });
|
2019-04-02 14:59:27 +00:00
|
|
|
expect(res).toBeNull();
|
2018-07-22 04:33:11 +00:00
|
|
|
});
|
2019-05-16 12:53:50 +00:00
|
|
|
it('replaces image-name value', () => {
|
|
|
|
const upgrade = {
|
2019-07-22 06:57:28 +00:00
|
|
|
managerData: { lineNumber: 102 },
|
2019-05-16 12:53:50 +00:00
|
|
|
depType: 'image-name',
|
|
|
|
depName: 'image-name-test',
|
|
|
|
newValue: '1.35',
|
|
|
|
};
|
2020-02-06 13:01:21 +00:00
|
|
|
const res = updateDependency({ fileContent: yamlFile, upgrade });
|
2019-05-16 12:53:50 +00:00
|
|
|
expect(res).not.toEqual(yamlFile);
|
|
|
|
});
|
|
|
|
it('returns same image-name value', () => {
|
|
|
|
const upgrade = {
|
2019-07-22 06:57:28 +00:00
|
|
|
managerData: { lineNumber: 102 },
|
2019-05-16 12:53:50 +00:00
|
|
|
depType: 'image-name',
|
|
|
|
depName: 'image-name-test',
|
|
|
|
newValue: '1.15',
|
|
|
|
};
|
2020-02-06 13:01:21 +00:00
|
|
|
const res = updateDependency({ fileContent: yamlFile, upgrade });
|
2019-05-16 12:53:50 +00:00
|
|
|
expect(res).toEqual(yamlFile);
|
|
|
|
});
|
2018-07-22 04:33:11 +00:00
|
|
|
it('replaces service-image update', () => {
|
|
|
|
const upgrade = {
|
2019-07-22 06:57:28 +00:00
|
|
|
managerData: { lineNumber: 55 },
|
2018-07-22 04:33:11 +00:00
|
|
|
depType: 'service-image',
|
|
|
|
depName: 'hadolint/hadolint',
|
|
|
|
newValue: '7.0.0',
|
|
|
|
newDigest: 'sha256:abcdefghijklmnop',
|
|
|
|
};
|
2020-02-06 13:01:21 +00:00
|
|
|
const res = updateDependency({ fileContent: yamlFile, upgrade });
|
2018-07-22 04:33:11 +00:00
|
|
|
expect(res).not.toEqual(yamlFile);
|
|
|
|
expect(res.includes(upgrade.newDigest)).toBe(true);
|
|
|
|
});
|
|
|
|
it('returns null if service-image mismatch', () => {
|
|
|
|
const upgrade = {
|
2019-07-22 06:57:28 +00:00
|
|
|
managerData: { lineNumber: 17 },
|
2018-07-22 04:33:11 +00:00
|
|
|
depType: 'service-image',
|
|
|
|
depName: 'postgres',
|
|
|
|
newValue: '9.6.8',
|
|
|
|
newDigest: 'sha256:abcdefghijklmnop',
|
|
|
|
};
|
2020-02-06 13:01:21 +00:00
|
|
|
const res = updateDependency({ fileContent: yamlFile, upgrade });
|
2019-04-02 14:59:27 +00:00
|
|
|
expect(res).toBeNull();
|
2018-07-22 04:33:11 +00:00
|
|
|
});
|
|
|
|
it('returns service-image same', () => {
|
|
|
|
const upgrade = {
|
|
|
|
depType: 'serviceimage',
|
2019-07-22 06:57:28 +00:00
|
|
|
managerData: { lineNumber: 55 },
|
2018-07-22 04:33:11 +00:00
|
|
|
depName: 'docker',
|
|
|
|
newValue: 'dind',
|
|
|
|
};
|
2020-02-06 13:01:21 +00:00
|
|
|
const res = updateDependency({ fileContent: yamlFile, upgrade });
|
2018-07-22 04:33:11 +00:00
|
|
|
expect(res).toEqual(yamlFile);
|
|
|
|
});
|
|
|
|
it('returns null if error', () => {
|
2020-02-06 13:01:21 +00:00
|
|
|
const res = updateDependency({ fileContent: null, upgrade: null });
|
2019-04-02 14:59:27 +00:00
|
|
|
expect(res).toBeNull();
|
2018-07-22 04:33:11 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|