-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.test.ts
40 lines (30 loc) · 1.32 KB
/
index.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import * as path from 'path';
import * as cdk8s from 'cdk8s';
import { ValidationContext } from 'cdk8s-cli/plugins';
// eslint-disable-next-line import/no-extraneous-dependencies
import * as kplus from 'cdk8s-plus-28';
import * as fs from 'fs-extra';
import * as yaml from 'yaml';
import { withTempDir } from './utils';
import { ExampleValidation } from '../src';
test('specific kinds can be ignored', async () => {
await withTempDir(async (dir: string) => {
// create a manifest that causes a violation
const chart = cdk8s.Testing.chart();
new kplus.Deployment(chart, 'Deployment', {
containers: [{ image: 'nginx' }],
restartPolicy: kplus.RestartPolicy.NEVER,
});
const manifest = chart.toJson();
const manifestPath = path.join(dir, 'manifest.yaml');
fs.writeFileSync(manifestPath, yaml.stringify(manifest));
// when used with cdk8s, cdk8s will instantiate both the plugin and
// the context for it. in our unit tests, we need to do it.
const validation = new ExampleValidation({ ignoreKinds: ['Deployment'] });
const context = new ValidationContext([manifestPath], 'cdk8s-validation-plugin-example', '0.0.0');
// run the validation
await validation.validate(context);
const report = context.report.toJson();
expect(report.violations.length).toEqual(0);
});
});