2020-02-05 00:14:31 +00:00
|
|
|
import * as manager from '.';
|
2020-04-06 17:38:20 +00:00
|
|
|
import { ManagerApi } from './common';
|
|
|
|
import { loadModules } from '../util/modules';
|
2017-10-25 04:48:08 +00:00
|
|
|
|
2017-10-25 04:00:07 +00:00
|
|
|
describe('manager', () => {
|
2018-05-09 06:03:59 +00:00
|
|
|
describe('get()', () => {
|
|
|
|
it('gets something', () => {
|
2020-02-04 09:37:24 +00:00
|
|
|
expect(manager.get('dockerfile', 'extractPackageFile')).not.toBeNull();
|
2018-04-30 14:13:32 +00:00
|
|
|
});
|
2017-10-25 04:00:07 +00:00
|
|
|
});
|
2018-05-09 06:03:59 +00:00
|
|
|
describe('getLanguageList()', () => {
|
|
|
|
it('gets', () => {
|
2019-04-02 14:59:27 +00:00
|
|
|
expect(manager.getLanguageList()).not.toBeNull();
|
2017-10-25 04:48:08 +00:00
|
|
|
});
|
2018-05-09 06:03:59 +00:00
|
|
|
});
|
|
|
|
describe('getManagerList()', () => {
|
|
|
|
it('gets', () => {
|
2019-04-02 14:59:27 +00:00
|
|
|
expect(manager.getManagerList()).not.toBeNull();
|
2017-10-25 04:48:08 +00:00
|
|
|
});
|
2018-05-09 06:03:59 +00:00
|
|
|
});
|
2020-04-06 17:38:20 +00:00
|
|
|
|
|
|
|
it('validates', () => {
|
|
|
|
function validate(module: ManagerApi): boolean {
|
|
|
|
if (!module.defaultConfig) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!module.extractPackageFile && !module.extractAllPackageFiles) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
const mgrs = manager.getManagers();
|
|
|
|
|
|
|
|
const loadedMgr = loadModules(__dirname, validate);
|
|
|
|
expect(Array.from(mgrs.keys())).toEqual(Object.keys(loadedMgr));
|
|
|
|
|
|
|
|
for (const name of mgrs.keys()) {
|
|
|
|
const mgr = mgrs.get(name);
|
|
|
|
expect(validate(mgr)).toBe(true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-11-05 06:47:44 +00:00
|
|
|
describe('extractAllPackageFiles()', () => {
|
2018-05-09 06:03:59 +00:00
|
|
|
it('returns null', () => {
|
2020-04-06 17:38:20 +00:00
|
|
|
manager.getManagers().set('dummy', {
|
|
|
|
defaultConfig: {},
|
|
|
|
});
|
2019-07-25 06:17:19 +00:00
|
|
|
expect(
|
2020-04-06 17:38:20 +00:00
|
|
|
manager.extractAllPackageFiles('unknown', {} as any, [])
|
2019-07-25 06:17:19 +00:00
|
|
|
).toBeNull();
|
2020-04-06 17:38:20 +00:00
|
|
|
expect(manager.extractAllPackageFiles('dummy', {} as any, [])).toBeNull();
|
2017-10-25 04:48:08 +00:00
|
|
|
});
|
2018-11-05 06:47:44 +00:00
|
|
|
it('returns non-null', () => {
|
2020-04-06 17:38:20 +00:00
|
|
|
manager.getManagers().set('dummy', {
|
|
|
|
defaultConfig: {},
|
|
|
|
extractAllPackageFiles: () => Promise.resolve([]),
|
|
|
|
});
|
2019-07-25 06:17:19 +00:00
|
|
|
expect(
|
2020-04-06 17:38:20 +00:00
|
|
|
manager.extractAllPackageFiles('dummy', {} as any, [])
|
2019-07-25 06:17:19 +00:00
|
|
|
).not.toBeNull();
|
|
|
|
});
|
2020-04-06 17:38:20 +00:00
|
|
|
afterEach(() => {
|
|
|
|
manager.getManagers().delete('dummy');
|
|
|
|
});
|
2019-07-25 06:17:19 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('extractPackageFile()', () => {
|
|
|
|
it('returns null', () => {
|
2020-04-06 17:38:20 +00:00
|
|
|
manager.getManagers().set('dummy', {
|
|
|
|
defaultConfig: {},
|
|
|
|
});
|
2019-07-25 06:17:19 +00:00
|
|
|
expect(manager.extractPackageFile('unknown', null)).toBeNull();
|
2020-04-06 17:38:20 +00:00
|
|
|
expect(manager.extractPackageFile('dummy', null)).toBeNull();
|
|
|
|
});
|
|
|
|
it('returns non-null', () => {
|
|
|
|
manager.getManagers().set('dummy', {
|
|
|
|
defaultConfig: {},
|
|
|
|
extractPackageFile: () => Promise.resolve({ deps: [] }),
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(manager.extractPackageFile('dummy', null)).not.toBeNull();
|
|
|
|
});
|
|
|
|
afterEach(() => {
|
|
|
|
manager.getManagers().delete('dummy');
|
2019-07-25 06:17:19 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('getPackageUpdates', () => {
|
|
|
|
it('returns null', () => {
|
2020-04-06 17:38:20 +00:00
|
|
|
manager.getManagers().set('dummy', {
|
|
|
|
defaultConfig: {},
|
|
|
|
});
|
2019-07-25 06:17:19 +00:00
|
|
|
expect(manager.getPackageUpdates('unknown', null)).toBeNull();
|
2020-04-06 17:38:20 +00:00
|
|
|
expect(manager.getPackageUpdates('dummy', null)).toBeNull();
|
|
|
|
});
|
|
|
|
it('returns non-null', () => {
|
|
|
|
manager.getManagers().set('dummy', {
|
|
|
|
defaultConfig: {},
|
|
|
|
getPackageUpdates: () => Promise.resolve([]),
|
|
|
|
});
|
|
|
|
expect(manager.getPackageUpdates('dummy', {} as any)).not.toBeNull();
|
|
|
|
});
|
|
|
|
afterEach(() => {
|
|
|
|
manager.getManagers().delete('dummy');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('getRangeStrategy', () => {
|
|
|
|
it('returns null', () => {
|
|
|
|
manager.getManagers().set('dummy', {
|
|
|
|
defaultConfig: {},
|
|
|
|
});
|
|
|
|
expect(
|
|
|
|
manager.getRangeStrategy({ manager: 'unknown', rangeStrategy: 'auto' })
|
|
|
|
).toBeNull();
|
|
|
|
});
|
|
|
|
it('returns non-null', () => {
|
|
|
|
manager.getManagers().set('dummy', {
|
|
|
|
defaultConfig: {},
|
|
|
|
getRangeStrategy: () => 'replace',
|
|
|
|
});
|
|
|
|
expect(
|
|
|
|
manager.getRangeStrategy({ manager: 'dummy', rangeStrategy: 'auto' })
|
|
|
|
).not.toBeNull();
|
|
|
|
|
|
|
|
manager.getManagers().set('dummy', {
|
|
|
|
defaultConfig: {},
|
|
|
|
});
|
|
|
|
expect(
|
|
|
|
manager.getRangeStrategy({ manager: 'dummy', rangeStrategy: 'auto' })
|
|
|
|
).not.toBeNull();
|
|
|
|
|
|
|
|
expect(
|
|
|
|
manager.getRangeStrategy({ manager: 'dummy', rangeStrategy: 'bump' })
|
|
|
|
).not.toBeNull();
|
|
|
|
});
|
|
|
|
afterEach(() => {
|
|
|
|
manager.getManagers().delete('dummy');
|
2017-10-25 04:48:08 +00:00
|
|
|
});
|
|
|
|
});
|
2017-10-25 04:00:07 +00:00
|
|
|
});
|