mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-12 23:16:26 +00:00
test: Refactor docker versioning tests (#11516)
This commit is contained in:
parent
3f5d13ee47
commit
f1d22c98f4
1 changed files with 170 additions and 184 deletions
|
@ -2,128 +2,122 @@ import semver from '../semver';
|
||||||
import docker from '.';
|
import docker from '.';
|
||||||
|
|
||||||
describe('versioning/docker/index', () => {
|
describe('versioning/docker/index', () => {
|
||||||
describe('isValid(version)', () => {
|
test.each`
|
||||||
it('should support all versions length', () => {
|
version | expected
|
||||||
expect(docker.isValid(null)).toBeNull();
|
${null} | ${false}
|
||||||
expect(docker.isValid('1.2.3')).toBe('1.2.3');
|
${'1.2.3'} | ${true}
|
||||||
expect(docker.isValid('18.04')).toBe('18.04');
|
${'18.04'} | ${true}
|
||||||
expect(docker.isValid('10.1')).toBe('10.1');
|
${'10.1'} | ${true}
|
||||||
expect(docker.isValid('3')).toBe('3');
|
${'3'} | ${true}
|
||||||
expect(docker.isValid('foo')).toBeNull();
|
${'foo'} | ${false}
|
||||||
});
|
${'0a1b2c3'} | ${false}
|
||||||
it('should return null if the version string looks like a git commit hash', () => {
|
${'0a1b2c3d'} | ${false}
|
||||||
[
|
${'0a1b2c3d4e5f6a7b8c9d0a1b2c3d4e5f6a7b8c9d'} | ${false}
|
||||||
'0a1b2c3',
|
${'0a1b2c3d4e5f6a7b8c9d0a1b2c3d4e5f6a7b8c9d0'} | ${true}
|
||||||
'0a1b2c3d',
|
${'0a1b2C3'} | ${true}
|
||||||
'0a1b2c3d4e5f6a7b8c9d0a1b2c3d4e5f6a7b8c9d',
|
${'0z1b2c3'} | ${true}
|
||||||
].forEach((version) => {
|
${'0A1b2c3d4e5f6a7b8c9d0a1b2c3d4e5f6a7b8c9d'} | ${true}
|
||||||
expect(docker.isValid(version)).toBeNull();
|
${'123098140293'} | ${true}
|
||||||
});
|
`('isValid("$version") === $expected', ({ version, expected }) => {
|
||||||
[
|
const res = docker.isValid(version);
|
||||||
'0a1b2c3d4e5f6a7b8c9d0a1b2c3d4e5f6a7b8c9d0',
|
expect(!!res).toBe(expected);
|
||||||
'0a1b2C3',
|
|
||||||
'0z1b2c3',
|
|
||||||
'0A1b2c3d4e5f6a7b8c9d0a1b2c3d4e5f6a7b8c9d',
|
|
||||||
'123098140293',
|
|
||||||
].forEach((version) => {
|
|
||||||
expect(docker.isValid(version)).toBe(version);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
describe('getMajor(version)', () => {
|
|
||||||
it('should support all versions length', () => {
|
test.each`
|
||||||
expect(docker.getMajor('1.2.3')).toBe(1);
|
version | major | minor | patch
|
||||||
expect(docker.getMajor('18.04')).toBe(18);
|
${'1.2.3'} | ${1} | ${2} | ${3}
|
||||||
expect(docker.getMajor('10.1')).toBe(10);
|
${'18.04'} | ${18} | ${4} | ${null}
|
||||||
expect(docker.getMajor('3')).toBe(3);
|
${'10.1'} | ${10} | ${1} | ${null}
|
||||||
expect(docker.getMajor('foo')).toBeNull();
|
${'3'} | ${3} | ${null} | ${null}
|
||||||
});
|
${'foo'} | ${null} | ${null} | ${null}
|
||||||
|
`(
|
||||||
|
'getMajor, getMinor, getPatch for "$version"',
|
||||||
|
({ version, major, minor, patch }) => {
|
||||||
|
expect(docker.getMajor(version)).toBe(major);
|
||||||
|
expect(docker.getMinor(version)).toBe(minor);
|
||||||
|
expect(docker.getPatch(version)).toBe(patch);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
test.each`
|
||||||
|
a | b | expected
|
||||||
|
${'1.2.3'} | ${'1.2'} | ${false}
|
||||||
|
${'18.04'} | ${'18.1'} | ${true}
|
||||||
|
${'10.1'} | ${'10.1.2'} | ${true}
|
||||||
|
${'3'} | ${'2'} | ${true}
|
||||||
|
${'1.2.3'} | ${'1.2.3'} | ${false}
|
||||||
|
`('isGreaterThan($a, $b) === $expected', ({ a, b, expected }) => {
|
||||||
|
expect(docker.isGreaterThan(a, b)).toBe(expected);
|
||||||
});
|
});
|
||||||
describe('getMinor(version)', () => {
|
|
||||||
it('should support all versions length', () => {
|
test.each`
|
||||||
expect(docker.getMinor('1.2.3')).toBe(2);
|
version | range | expected
|
||||||
expect(docker.getMinor('18.04')).toBe(4);
|
${'1.2.3'} | ${'2.0'} | ${true}
|
||||||
expect(docker.getMinor('10.1')).toBe(1);
|
${'18.04'} | ${'18.1'} | ${false}
|
||||||
expect(docker.getMinor('3')).toBeNull();
|
${'10.1'} | ${'10.0.4'} | ${false}
|
||||||
expect(docker.getMinor('foo')).toBeNull();
|
${'3'} | ${'4.0'} | ${true}
|
||||||
});
|
${'1.2'} | ${'1.3.4'} | ${true}
|
||||||
|
`(
|
||||||
|
'isLessThanRange($version, $range) === $expected',
|
||||||
|
({ version, range, expected }) => {
|
||||||
|
expect(docker.isLessThanRange(version, range)).toBe(expected);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
test.each`
|
||||||
|
a | b | expected
|
||||||
|
${'1.2.3'} | ${'1.2.3'} | ${true}
|
||||||
|
${'18.04'} | ${'18.4'} | ${true}
|
||||||
|
${'10.0'} | ${'10.0.4'} | ${false}
|
||||||
|
${'3'} | ${'4.0'} | ${false}
|
||||||
|
${'1.2'} | ${'1.2.3'} | ${false}
|
||||||
|
`('equals($a, $b) === $expected', ({ a, b, expected }) => {
|
||||||
|
expect(docker.equals(a, b)).toBe(expected);
|
||||||
});
|
});
|
||||||
describe('getPatch(version)', () => {
|
|
||||||
it('should support all versions length', () => {
|
describe('Satisfying versions', () => {
|
||||||
expect(docker.getPatch('1.2.3')).toBe(3);
|
const versions = [
|
||||||
expect(docker.getPatch('18.04')).toBeNull();
|
'0.9.8',
|
||||||
expect(docker.getPatch('10.1')).toBeNull();
|
'1.1.1',
|
||||||
expect(docker.getPatch('3')).toBeNull();
|
'1.1',
|
||||||
expect(docker.getPatch('foo')).toBeNull();
|
'1.2.3',
|
||||||
|
'1.2',
|
||||||
|
'1',
|
||||||
|
'2.2.2',
|
||||||
|
'2.2',
|
||||||
|
'2',
|
||||||
|
];
|
||||||
|
|
||||||
|
test.each`
|
||||||
|
version | expected
|
||||||
|
${'1.2.3'} | ${'1.2.3'}
|
||||||
|
${'1.2'} | ${'1.2'}
|
||||||
|
${'1'} | ${'1'}
|
||||||
|
${'1.3'} | ${null}
|
||||||
|
${'0.9'} | ${null}
|
||||||
|
`(`satisfying for $version -> $expected`, ({ version, expected }) => {
|
||||||
|
const satisfying = docker.getSatisfyingVersion(versions, version);
|
||||||
|
const minSatisfying = docker.minSatisfyingVersion(versions, version);
|
||||||
|
expect(satisfying).toBe(expected);
|
||||||
|
expect(minSatisfying).toBe(expected);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('isGreaterThan(version, other)', () => {
|
|
||||||
it('should support all versions length', () => {
|
|
||||||
expect(docker.isGreaterThan('1.2.3', '1.2')).toBe(false);
|
|
||||||
expect(docker.isGreaterThan('18.04', '18.1')).toBe(true);
|
|
||||||
expect(docker.isGreaterThan('10.1', '10.1.2')).toBe(true);
|
|
||||||
expect(docker.isGreaterThan('3', '2')).toBe(true);
|
|
||||||
expect(docker.isGreaterThan('1.2.3', '1.2.3')).toBe(false);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
describe('isLessThanRange(version, range)', () => {
|
|
||||||
it('should support all versions length', () => {
|
|
||||||
expect(docker.isLessThanRange('1.2.3', '2.0')).toBe(true);
|
|
||||||
expect(docker.isLessThanRange('18.04', '18.1')).toBe(false);
|
|
||||||
expect(docker.isLessThanRange('10.1', '10.0.4')).toBe(false);
|
|
||||||
expect(docker.isLessThanRange('3', '4.0')).toBe(true);
|
|
||||||
expect(docker.isLessThanRange('1.2', '1.3.4')).toBe(true);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
describe('equals(version, other)', () => {
|
|
||||||
it('should support all versions length', () => {
|
|
||||||
expect(docker.equals('1.2.3', '1.2.3')).toBe(true);
|
|
||||||
expect(docker.equals('18.04', '18.4')).toBe(true);
|
|
||||||
expect(docker.equals('10.0', '10.0.4')).toBe(false);
|
|
||||||
expect(docker.equals('3', '4.0')).toBe(false);
|
|
||||||
expect(docker.equals('1.2', '1.2.3')).toBe(false);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
describe('getSatisfyingVersion(versions, range)', () => {
|
|
||||||
it('should support all versions length', () => {
|
|
||||||
[docker.minSatisfyingVersion, docker.getSatisfyingVersion].forEach(
|
|
||||||
(max) => {
|
|
||||||
const versions = [
|
|
||||||
'0.9.8',
|
|
||||||
'1.1.1',
|
|
||||||
'1.1',
|
|
||||||
'1.2.3',
|
|
||||||
'1.2',
|
|
||||||
'1',
|
|
||||||
'2.2.2',
|
|
||||||
'2.2',
|
|
||||||
'2',
|
|
||||||
];
|
|
||||||
// returns range if found
|
|
||||||
expect(max(versions, '1.2.3')).toBe('1.2.3');
|
|
||||||
expect(max(versions, '1.2')).toBe('1.2');
|
|
||||||
expect(max(versions, '1')).toBe('1');
|
|
||||||
// return null if not found
|
|
||||||
expect(max(versions, '1.3')).toBeNull();
|
|
||||||
expect(max(versions, '0.9')).toBeNull();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
describe('sortVersions(v1, v2)', () => {
|
describe('sortVersions(v1, v2)', () => {
|
||||||
it('behaves like semver.sortVersions', () => {
|
test.each`
|
||||||
[
|
a | b
|
||||||
['1.1.1', '1.2.3'],
|
${'1.1.1'} | ${'1.2.3'}
|
||||||
['1.2.3', '1.3.4'],
|
${'1.2.3'} | ${'1.3.4'}
|
||||||
['2.0.1', '1.2.3'],
|
${'2.0.1'} | ${'1.2.3'}
|
||||||
['1.2.3', '0.9.5'],
|
${'1.2.3'} | ${'0.9.5'}
|
||||||
].forEach((pair) => {
|
`(
|
||||||
expect(docker.sortVersions(pair[0], pair[1])).toBe(
|
'docker.sortVersions("$a", "$b") === semver.sortVersions("$a", "$b")',
|
||||||
semver.sortVersions(pair[0], pair[1])
|
({ a, b }) => {
|
||||||
);
|
const dockerSorted = docker.sortVersions(a, b);
|
||||||
});
|
const semverSorted = semver.sortVersions(a, b);
|
||||||
});
|
expect(dockerSorted).toBe(semverSorted);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
it('sorts unstable', () => {
|
it('sorts unstable', () => {
|
||||||
const versions = [
|
const versions = [
|
||||||
|
@ -149,77 +143,69 @@ describe('versioning/docker/index', () => {
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('getNewValue(', () => {
|
|
||||||
it('returns newVersion', () => {
|
test.each`
|
||||||
expect(
|
currentValue | rangeStrategy | currentVersion | newVersion | expected
|
||||||
docker.getNewValue({
|
${null} | ${null} | ${null} | ${'1.2.3'} | ${'1.2.3'}
|
||||||
currentValue: null,
|
`(
|
||||||
rangeStrategy: null,
|
'getNewValue($currentValue, $rangeStrategy, $currentVersion, $newVersion, $expected) === $expected',
|
||||||
currentVersion: null,
|
({ currentValue, rangeStrategy, currentVersion, newVersion, expected }) => {
|
||||||
newVersion: '1.2.3',
|
const res = docker.getNewValue({
|
||||||
})
|
currentValue,
|
||||||
).toBe('1.2.3');
|
rangeStrategy,
|
||||||
});
|
currentVersion,
|
||||||
|
newVersion,
|
||||||
|
});
|
||||||
|
expect(res).toBe(expected);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
test.each`
|
||||||
|
version | expected
|
||||||
|
${'3.7.0'} | ${true}
|
||||||
|
${'3.7.0b1'} | ${false}
|
||||||
|
${'3.7-alpine'} | ${true}
|
||||||
|
${'3.8.0-alpine'} | ${true}
|
||||||
|
${'3.8.0b1-alpine'} | ${false}
|
||||||
|
${'3.8.2'} | ${true}
|
||||||
|
`('isStable("$version") === $expected', ({ version, expected }) => {
|
||||||
|
const res = docker.isStable(version);
|
||||||
|
expect(!!res).toBe(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('isStable(version)', () => {
|
test.each`
|
||||||
const versions = [
|
version | range | expected
|
||||||
'3.7.0',
|
${'3.7.0'} | ${'3.7.0'} | ${true}
|
||||||
'3.7.0b1',
|
${'3.7.0b1'} | ${'3.7.0'} | ${true}
|
||||||
'3.7-alpine',
|
${'3.7-alpine'} | ${'3.7.0'} | ${false}
|
||||||
'3.8.0-alpine',
|
${'3.8.0-alpine'} | ${'3.7.0'} | ${false}
|
||||||
'3.8.0b1-alpine',
|
${'3.8.0b1-alpine'} | ${'3.7.0'} | ${false}
|
||||||
'3.8.2',
|
${'3.8.2'} | ${'3.7.0'} | ${true}
|
||||||
];
|
${'3.7.0'} | ${'3.7.0-alpine'} | ${false}
|
||||||
|
${'3.7.0b1'} | ${'3.7.0-alpine'} | ${false}
|
||||||
|
${'3.7-alpine'} | ${'3.7.0-alpine'} | ${false}
|
||||||
|
${'3.8.0-alpine'} | ${'3.7.0-alpine'} | ${true}
|
||||||
|
${'3.8.0b1-alpine'} | ${'3.7.0-alpine'} | ${true}
|
||||||
|
${'3.8.2'} | ${'3.7.0-alpine'} | ${false}
|
||||||
|
`(
|
||||||
|
'isCompatible("$version") === $expected',
|
||||||
|
({ version, range, expected }) => {
|
||||||
|
const res = docker.isCompatible(version, range);
|
||||||
|
expect(!!res).toBe(expected);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
expect(versions.filter(docker.isStable)).toEqual([
|
test.each`
|
||||||
'3.7.0',
|
value | expected
|
||||||
'3.7-alpine',
|
${'3.7.0'} | ${'3.7.0'}
|
||||||
'3.8.0-alpine',
|
${'3.7.0b1'} | ${'3.7.0b1'}
|
||||||
'3.8.2',
|
${'3.7-alpine'} | ${'3.7'}
|
||||||
]);
|
${'3.8.0-alpine'} | ${'3.8.0'}
|
||||||
});
|
${'3.8.0b1-alpine'} | ${'3.8.0b1'}
|
||||||
|
${'3.8.2'} | ${'3.8.2'}
|
||||||
it('isCompatible(version)', () => {
|
${undefined} | ${undefined}
|
||||||
const versions = [
|
`('valueToVersion("$value") === $expected', ({ value, expected }) => {
|
||||||
'3.7.0',
|
const res = docker.valueToVersion(value);
|
||||||
'3.7.0b1',
|
expect(res).toBe(expected);
|
||||||
'3.7-alpine',
|
|
||||||
'3.8.0-alpine',
|
|
||||||
'3.8.0b1-alpine',
|
|
||||||
'3.8.2',
|
|
||||||
];
|
|
||||||
|
|
||||||
expect(versions.filter((v) => docker.isCompatible(v, '3.7.0'))).toEqual([
|
|
||||||
'3.7.0',
|
|
||||||
'3.7.0b1',
|
|
||||||
'3.8.2',
|
|
||||||
]);
|
|
||||||
|
|
||||||
expect(
|
|
||||||
versions.filter((v) => docker.isCompatible(v, '3.7.0-alpine'))
|
|
||||||
).toEqual(['3.8.0-alpine', '3.8.0b1-alpine']);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('valueToVersion(version)', () => {
|
|
||||||
const versions = [
|
|
||||||
'3.7.0',
|
|
||||||
'3.7.0b1',
|
|
||||||
'3.7-alpine',
|
|
||||||
'3.8.0-alpine',
|
|
||||||
'3.8.0b1-alpine',
|
|
||||||
'3.8.2',
|
|
||||||
undefined,
|
|
||||||
];
|
|
||||||
|
|
||||||
expect(versions.map(docker.valueToVersion)).toEqual([
|
|
||||||
'3.7.0',
|
|
||||||
'3.7.0b1',
|
|
||||||
'3.7',
|
|
||||||
'3.8.0',
|
|
||||||
'3.8.0b1',
|
|
||||||
'3.8.2',
|
|
||||||
undefined,
|
|
||||||
]);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue