|
15 | 15 | */ |
16 | 16 |
|
17 | 17 | import { FileFormat, parse, stringify } from './io'; |
18 | | -import { Configs, KubernetesObject } from './types'; |
| 18 | +import { Configs, JsonArray, KubernetesObject } from './types'; |
| 19 | +import { kubernetesObjectResult } from './result'; |
19 | 20 |
|
20 | 21 | describe('read', () => { |
21 | 22 | describe('in YAML format', () => { |
@@ -686,3 +687,68 @@ results: |
686 | 687 | }); |
687 | 688 | }); |
688 | 689 | }); |
| 690 | + |
| 691 | +describe('roundtrip', () => { |
| 692 | + describe('using YAML', () => { |
| 693 | + it('should not insert YAML references', () => { |
| 694 | + interface Baz { |
| 695 | + baz: number; |
| 696 | + } |
| 697 | + |
| 698 | + interface Foo extends KubernetesObject { |
| 699 | + spec: { |
| 700 | + array: Baz[]; |
| 701 | + }; |
| 702 | + } |
| 703 | + |
| 704 | + const input = |
| 705 | + 'items: [{apiVersion: v1, kind: Foo, metadata: {name: bar}, spec: {array: [{baz: 1}]}}]'; |
| 706 | + const configs = parse(input, FileFormat.YAML); |
| 707 | + |
| 708 | + const foo = configs.getAll()[0] as Foo; |
| 709 | + configs.addResults( |
| 710 | + kubernetesObjectResult('something is wrong', foo, { |
| 711 | + path: 'spec.array', |
| 712 | + // Note: we re-use objects from the input to trigger YAML refs to normally be created |
| 713 | + currentValue: (foo.spec.array as unknown) as JsonArray, |
| 714 | + suggestedValue: (foo.spec.array.concat([ |
| 715 | + { baz: 3 }, |
| 716 | + ]) as unknown) as JsonArray, |
| 717 | + }) |
| 718 | + ); |
| 719 | + |
| 720 | + const stringified = stringify(configs, FileFormat.YAML); |
| 721 | + |
| 722 | + // We want to verify that there are no back-references like &ref and *ref in the output |
| 723 | + expect(stringified).toEqual(`apiVersion: v1 |
| 724 | +kind: ResourceList |
| 725 | +metadata: |
| 726 | + name: output |
| 727 | +items: |
| 728 | +- apiVersion: v1 |
| 729 | + kind: Foo |
| 730 | + metadata: |
| 731 | + name: bar |
| 732 | + spec: |
| 733 | + array: |
| 734 | + - baz: 1 |
| 735 | +results: |
| 736 | +- message: something is wrong |
| 737 | + severity: error |
| 738 | + resourceRef: |
| 739 | + apiVersion: v1 |
| 740 | + kind: Foo |
| 741 | + namespace: '' |
| 742 | + name: bar |
| 743 | + file: {} |
| 744 | + field: |
| 745 | + path: spec.array |
| 746 | + currentValue: |
| 747 | + - baz: 1 |
| 748 | + suggestedValue: |
| 749 | + - baz: 1 |
| 750 | + - baz: 3 |
| 751 | +`); |
| 752 | + }); |
| 753 | + }); |
| 754 | +}); |
0 commit comments