renovate/lib/manager/terraform/extract.spec.ts

57 lines
1.8 KiB
TypeScript
Raw Normal View History

import { readFileSync } from 'fs';
import {
TerraformDependencyTypes,
2020-05-01 16:03:48 +00:00
extractPackageFile,
getTerraformDependencyType,
} from './extract';
const tf1 = readFileSync('lib/manager/terraform/__fixtures__/1.tf', 'utf8');
const tf2 = `module "relative" {
source = "../../modules/fe"
}
`;
describe('lib/manager/terraform/extract', () => {
describe('extractPackageFile()', () => {
it('returns null for empty', () => {
2019-07-17 08:14:56 +00:00
expect(extractPackageFile('nothing here')).toBeNull();
});
it('extracts', () => {
const res = extractPackageFile(tf1);
expect(res).toMatchSnapshot();
expect(res.deps).toHaveLength(22);
expect(res.deps.filter((dep) => dep.skipReason)).toHaveLength(6);
});
it('returns null if only local deps', () => {
2019-07-17 08:14:56 +00:00
expect(extractPackageFile(tf2)).toBeNull();
});
});
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
);
});
});
});