forked from serverless/serverless
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathYamlParser.js
More file actions
89 lines (66 loc) · 2.54 KB
/
YamlParser.js
File metadata and controls
89 lines (66 loc) · 2.54 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
'use strict';
/**
* Test: YamlParser Function Class
*/
const expect = require('chai').expect;
const YAML = require('js-yaml');
const path = require('path');
const os = require('os');
const Serverless = require('../../lib/Serverless');
const serverless = new Serverless();
describe('YamlParser', () => {
describe('#parse()', () => {
it('should parse a simple yaml file', () => {
const tmpFilePath = path.join(os.tmpdir(), (new Date).getTime().toString(), 'simple.yml');
serverless.utils.writeFileSync(tmpFilePath, YAML.dump({ foo: 'bar' }));
return serverless.yamlParser.parse(tmpFilePath).then((obj) => {
expect(obj.foo).to.equal('bar');
});
});
it('should parse a yaml file with JSON-REF to yaml', () => {
const tmpDirPath = path.join(os.tmpdir(), (new Date).getTime().toString());
serverless.utils.writeFileSync(path.join(tmpDirPath, 'ref.yaml'), { foo: 'bar' });
const testYaml = {
main: {
$ref: './ref.yaml',
},
};
serverless.utils.writeFileSync(path.join(tmpDirPath, 'test.yaml'), testYaml);
return serverless.yamlParser.parse(path.join(tmpDirPath, 'test.yaml')).then((obj) => {
expect(obj.main.foo).to.equal('bar');
});
});
it('should parse a yaml file with JSON-REF to json', () => {
const tmpDirPath = path.join(os.tmpdir(), (new Date).getTime().toString());
serverless.utils.writeFileSync(path.join(tmpDirPath, 'ref.json'), { foo: 'bar' });
const testYaml = {
main: {
$ref: './ref.json',
},
};
serverless.utils.writeFileSync(path.join(tmpDirPath, 'test.yaml'), testYaml);
return serverless.yamlParser.parse(path.join(tmpDirPath, 'test.yaml')).then((obj) => {
expect(obj.main.foo).to.equal('bar');
});
});
it('should parse yaml file with recursive JSON-REF', () => {
const tmpDirPath = path.join(os.tmpdir(), (new Date).getTime().toString());
serverless.utils.writeFileSync(path.join(tmpDirPath, 'three.yaml'), { foo: 'bar' });
const twoYaml = {
two: {
$ref: './three.yaml',
},
};
serverless.utils.writeFileSync(path.join(tmpDirPath, 'two.yaml'), twoYaml);
const oneYaml = {
one: {
$ref: './two.yaml',
},
};
serverless.utils.writeFileSync(path.join(tmpDirPath, 'one.yaml'), oneYaml);
return serverless.yamlParser.parse(path.join(tmpDirPath, 'one.yaml')).then((obj) => {
expect(obj.one.two.foo).to.equal('bar');
});
});
});
});