forked from serverless/serverless
/
config.test.js
77 lines (69 loc) · 2.86 KB
/
config.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
'use strict';
const fs = require('fs');
const path = require('path');
const os = require('os');
const BbPromise = require('bluebird');
const { expect } = require('chai');
const { ServerlessError } = require('../../classes/Error');
const runServerless = require('../../../test/utils/run-serverless');
const isTabCompletionSupported = require('../../utils/tabCompletion/isSupported');
BbPromise.promisifyAll(fs);
const unexpected = () => {
throw new Error('Unexpected');
};
describe('Config', () => {
it('should support "config credentials" command', () =>
runServerless({
config: { service: 'foo', provider: 'aws' },
cliArgs: ['config', 'credentials', '--provider', 'aws', '-k', 'foo', '-s', 'bar'],
}));
it('should have a required option "provider" for the "credentials" sub-command', () =>
runServerless({
config: { service: 'foo', provider: 'aws' },
cliArgs: ['config', 'credentials', '-k', 'foo', '-s', 'bar'],
}).then(unexpected, error => expect(error).to.be.instanceof(ServerlessError)));
it('should throw an error if user passed unsupported "provider" option', () =>
runServerless({
config: { service: 'foo', provider: 'aws' },
cliArgs: ['config', 'credentials', '--provider', 'not-supported', '-k', 'foo', '-s', 'bar'],
}).then(unexpected, error => expect(error).to.be.instanceof(ServerlessError)));
if (isTabCompletionSupported) {
it('should support "config tabcompletion install" command', () =>
runServerless({
cwd: os.homedir(),
env: { SHELL: 'bash' },
cliArgs: ['config', 'tabcompletion', 'install'],
}).then(() =>
Promise.all([
fs
.readFileAsync(path.resolve(os.homedir(), '.bashrc'), 'utf8')
.then(bashRcContent =>
expect(bashRcContent).to.include(' ~/.config/tabtab/__tabtab.bash')
),
fs.readFileAsync(path.resolve(os.homedir(), '.config/tabtab/serverless.bash'), 'utf8'),
fs.readFileAsync(path.resolve(os.homedir(), '.config/tabtab/sls.bash'), 'utf8'),
])
));
it('should support "config tabcompletion uninstall" command', () =>
runServerless({
cwd: os.homedir(),
env: { SHELL: 'bash' },
cliArgs: ['config', 'tabcompletion', 'install'],
}).then(() =>
runServerless({
cwd: os.homedir(),
env: { SHELL: 'bash' },
cliArgs: ['config', 'tabcompletion', 'uninstall'],
}).then(() =>
Promise.all([
fs
.readFileAsync(path.resolve(os.homedir(), '.config/tabtab/serverless.bash'))
.then(unexpected, error => expect(error.code).to.equal('ENOENT')),
fs
.readFileAsync(path.resolve(os.homedir(), '.config/tabtab/sls.bash'))
.then(unexpected, error => expect(error.code).to.equal('ENOENT')),
])
)
));
}
});