forked from kubernetes-client/javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathyaml_test.ts
More file actions
46 lines (42 loc) · 1.56 KB
/
Copy pathyaml_test.ts
File metadata and controls
46 lines (42 loc) · 1.56 KB
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
41
42
43
44
45
46
import { expect } from 'chai';
import { V1Namespace } from './api';
import { dumpYaml, loadAllYaml, loadYaml } from './yaml';
describe('yaml', () => {
it('should load safely', () => {
const yaml = 'apiVersion: v1\n' + 'kind: Namespace\n' + 'metadata:\n' + ' name: some-namespace\n';
const ns = loadYaml<V1Namespace>(yaml);
expect(ns.apiVersion).to.equal('v1');
expect(ns.kind).to.equal('Namespace');
expect(ns.metadata!.name).to.equal('some-namespace');
});
it('should load all safely', () => {
const yaml =
'apiVersion: v1\n' +
'kind: Namespace\n' +
'metadata:\n' +
' name: some-namespace\n' +
'---\n' +
'apiVersion: v1\n' +
'kind: Pod\n' +
'metadata:\n' +
' name: some-pod\n' +
' namespace: some-ns\n';
const objects = loadAllYaml(yaml);
expect(objects.length).to.equal(2);
expect(objects[0].kind).to.equal('Namespace');
expect(objects[1].kind).to.equal('Pod');
expect(objects[0].metadata.name).to.equal('some-namespace');
expect(objects[1].metadata.name).to.equal('some-pod');
expect(objects[1].metadata.namespace).to.equal('some-ns');
});
it('should round trip successfully', () => {
const expected = {
metadata: {
name: 'test',
},
};
const yamlString = dumpYaml(expected);
const actual = loadYaml(yamlString);
expect(actual).to.deep.equal(expected);
});
});