2019-07-25 06:17:19 +00:00
|
|
|
import { readFileSync } from 'fs';
|
2019-12-15 06:51:00 +00:00
|
|
|
import {
|
|
|
|
TerraformDependencyTypes,
|
2020-05-01 16:03:48 +00:00
|
|
|
extractPackageFile,
|
2019-12-15 06:51:00 +00:00
|
|
|
getTerraformDependencyType,
|
2020-02-05 00:14:31 +00:00
|
|
|
} from './extract';
|
2018-10-06 11:39:39 +00:00
|
|
|
|
2020-02-11 05:08:10 +00:00
|
|
|
const tf1 = readFileSync('lib/manager/terraform/__fixtures__/1.tf', 'utf8');
|
2018-10-06 17:33:42 +00:00
|
|
|
const tf2 = `module "relative" {
|
|
|
|
source = "../../modules/fe"
|
|
|
|
}
|
|
|
|
`;
|
2018-10-06 11:39:39 +00:00
|
|
|
|
|
|
|
describe('lib/manager/terraform/extract', () => {
|
2018-11-04 17:51:23 +00:00
|
|
|
describe('extractPackageFile()', () => {
|
2018-10-06 11:39:39 +00:00
|
|
|
it('returns null for empty', () => {
|
2019-07-17 08:14:56 +00:00
|
|
|
expect(extractPackageFile('nothing here')).toBeNull();
|
2018-10-06 11:39:39 +00:00
|
|
|
});
|
|
|
|
it('extracts', () => {
|
2018-11-04 17:51:23 +00:00
|
|
|
const res = extractPackageFile(tf1);
|
2018-10-06 11:39:39 +00:00
|
|
|
expect(res).toMatchSnapshot();
|
2020-02-19 15:07:34 +00:00
|
|
|
expect(res.deps).toHaveLength(22);
|
2020-04-12 16:09:36 +00:00
|
|
|
expect(res.deps.filter((dep) => dep.skipReason)).toHaveLength(6);
|
2018-10-06 11:39:39 +00:00
|
|
|
});
|
2018-10-06 17:33:42 +00:00
|
|
|
it('returns null if only local deps', () => {
|
2019-07-17 08:14:56 +00:00
|
|
|
expect(extractPackageFile(tf2)).toBeNull();
|
2018-10-06 17:33:42 +00:00
|
|
|
});
|
2018-10-06 11:39:39 +00:00
|
|
|
});
|
2019-12-15 06:51:00 +00:00
|
|
|
describe('getTerraformDependencyType()', () => {
|
|
|
|
it('returns TerraformDependencyTypes.module', () => {
|
|
|
|
expect(getTerraformDependencyType('module')).toBe(
|
|
|
|
TerraformDependencyTypes.module
|
|
|
|
);
|
|
|
|
});
|
|
|
|
it('returns TerraformDependencyTypes.provider', () => {
|
|
|
|
expect(getTerraformDependencyType('provider')).toBe(
|
|
|
|
TerraformDependencyTypes.provider
|
|
|
|
);
|
|
|
|
});
|
|
|
|
it('returns TerraformDependencyTypes.unknown', () => {
|
|
|
|
expect(getTerraformDependencyType('unknown')).toBe(
|
|
|
|
TerraformDependencyTypes.unknown
|
|
|
|
);
|
|
|
|
});
|
|
|
|
it('returns TerraformDependencyTypes.unknown on empty string', () => {
|
|
|
|
expect(getTerraformDependencyType('')).toBe(
|
|
|
|
TerraformDependencyTypes.unknown
|
|
|
|
);
|
|
|
|
});
|
|
|
|
it('returns TerraformDependencyTypes.unknown on string with random chars', () => {
|
|
|
|
expect(getTerraformDependencyType('sdfsgdsfadfhfghfhgdfsdf')).toBe(
|
|
|
|
TerraformDependencyTypes.unknown
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2018-10-06 11:39:39 +00:00
|
|
|
});
|