/
configSchema.test.js
127 lines (120 loc) · 2.91 KB
/
configSchema.test.js
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
'use strict';
const runServerless = require('../test/utils/run-serverless');
const expect = require('chai').expect;
describe('#configSchema', () => {
const cases = [
{
isValid: true,
description: 'config',
mutation: {},
},
{
isValid: false,
errorMessage: 'should match pattern "^[a-zA-Z][0-9a-zA-Z-]+$"',
description: 'service name',
mutation: {
service: { name: '1-first-number-is-not-allowed' },
},
},
{
isValid: false,
errorMessage: 'should match pattern "^arn:aws[a-z-]*:kms',
description: 'service awsKmsKeyArn',
mutation: {
service: {
name: 'some-service',
awsKmsKeyArn: 'invalidArn',
},
},
},
{
isValid: true,
description: 'service awsKmsKeyArn',
mutation: {
service: {
name: 'some-service',
awsKmsKeyArn: 'arn:aws:kms:us-east-1:123456789012:key/some-hash',
},
},
},
{
isValid: false,
errorMessage: 'unrecognized property',
description: 'service unknown property',
mutation: {
service: {
name: 'some-service',
unknownProp: 'this is not supported',
},
},
},
{
isValid: true,
description: 'custom properties',
mutation: {
custom: {
some: 'valid property',
},
},
},
{
isValid: true,
description: 'functions',
mutation: {
functions: {
someFunc: {
events: [],
handler: 'someHandler',
name: 'some-service-dev-someFunc',
},
},
},
},
{
isValid: true,
logMessage: 'Unrecognized provider',
description: 'provider not existing name',
mutation: {
provider: { name: 'awssss' },
},
},
{
isValid: true,
description: 'package',
mutation: {
package: {
individually: true,
path: undefined,
artifact: 'path/to/my-artifact.zip',
exclude: ['.git/**', '.travis.yml'],
include: ['src/**', 'handler.js'],
excludeDevDependencies: false,
},
},
},
];
for (const someCase of cases) {
const passOrFail = someCase.isValid ? 'pass' : 'fail';
it(`should ${passOrFail} validation for ${someCase.description}`, () =>
runServerless({
fixture: 'configSchemaExtensions',
configExt: someCase.mutation,
cliArgs: ['info'],
}).then(
({ stdoutData }) => {
if (!someCase.isValid) {
expect(false).to.be.true;
}
if (someCase.logMessage) expect(stdoutData).to.include(someCase.logMessage);
return;
},
err => {
try {
expect(err.message).to.include(someCase.errorMessage);
} catch (error) {
throw err;
}
}
));
}
});