navy 6.0.0 → 7.0.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/__tests__/config-provider.js +75 -0
- package/lib/__tests__/config.js +130 -0
- package/lib/__tests__/driver-logging.js +148 -0
- package/lib/__tests__/driver.js +19 -0
- package/lib/__tests__/errors.js +49 -0
- package/lib/__tests__/http-proxy.js +214 -0
- package/lib/__tests__/index.js +25 -0
- package/lib/__tests__/service.js +16 -0
- package/lib/cli/__tests__/develop.js +239 -0
- package/lib/cli/__tests__/external-ip.js +68 -0
- package/lib/cli/__tests__/health.js +257 -0
- package/lib/cli/__tests__/https.js +210 -0
- package/lib/cli/__tests__/import.js +110 -0
- package/lib/cli/__tests__/index.js +118 -0
- package/lib/cli/__tests__/lan-ip.js +90 -0
- package/lib/cli/__tests__/launch.js +179 -0
- package/lib/cli/__tests__/live.js +155 -0
- package/lib/cli/__tests__/local-ip.js +72 -0
- package/lib/cli/__tests__/logs.js +52 -0
- package/lib/cli/__tests__/open.js +65 -0
- package/lib/cli/__tests__/program.js +472 -0
- package/lib/cli/__tests__/ps.js +345 -0
- package/lib/cli/__tests__/refresh-config.js +95 -0
- package/lib/cli/__tests__/run.js +54 -0
- package/lib/cli/__tests__/status.js +204 -0
- package/lib/cli/__tests__/updates.js +243 -0
- package/lib/cli/__tests__/wait-for-healthy.js +134 -0
- package/lib/cli/config/__tests__/index.js +275 -0
- package/lib/cli/config/__tests__/wrapper.js +53 -0
- package/lib/cli/config/index.js +19 -37
- package/lib/cli/config/wrapper.js +0 -6
- package/lib/cli/develop.js +7 -21
- package/lib/cli/doctor/__tests__/clean-compose-files.js +78 -0
- package/lib/cli/doctor/__tests__/index.js +67 -0
- package/lib/cli/doctor/__tests__/invalid-compose-config.js +103 -0
- package/lib/cli/doctor/__tests__/invalid-state.js +83 -0
- package/lib/cli/doctor/__tests__/util.js +91 -0
- package/lib/cli/doctor/clean-compose-files.js +5 -13
- package/lib/cli/doctor/index.js +0 -12
- package/lib/cli/doctor/invalid-compose-config.js +0 -4
- package/lib/cli/doctor/invalid-state.js +0 -6
- package/lib/cli/doctor/util.js +0 -10
- package/lib/cli/external-ip.js +0 -4
- package/lib/cli/health.js +0 -12
- package/lib/cli/https.js +9 -25
- package/lib/cli/import.js +0 -12
- package/lib/cli/index.js +0 -9
- package/lib/cli/lan-ip.js +2 -8
- package/lib/cli/launch.js +0 -9
- package/lib/cli/live.js +6 -16
- package/lib/cli/local-ip.js +2 -7
- package/lib/cli/logs.js +0 -3
- package/lib/cli/open.js +2 -7
- package/lib/cli/program.js +73 -101
- package/lib/cli/ps.js +1 -21
- package/lib/cli/refresh-config.js +0 -7
- package/lib/cli/run.js +0 -3
- package/lib/cli/status.js +0 -11
- package/lib/cli/updates.js +0 -22
- package/lib/cli/util/__tests__/get-or-initialise-navy.js +66 -0
- package/lib/cli/util/__tests__/import.js +123 -0
- package/lib/cli/util/__tests__/index.js +17 -0
- package/lib/cli/util/__tests__/merge-action-options.js +47 -0
- package/lib/cli/util/__tests__/reconfigure.js +78 -0
- package/lib/cli/util/get-or-initialise-navy.js +0 -7
- package/lib/cli/util/import.js +0 -9
- package/lib/cli/util/index.js +0 -2
- package/lib/cli/util/merge-action-options.js +20 -0
- package/lib/cli/util/reconfigure.js +0 -4
- package/lib/cli/wait-for-healthy.js +0 -21
- package/lib/client/registry/__tests__/get-credentials.js +62 -0
- package/lib/client/registry/__tests__/get-endpoint.js +124 -0
- package/lib/client/registry/__tests__/get-fat-manifest.js +67 -0
- package/lib/client/registry/__tests__/get-token.js +66 -0
- package/lib/client/registry/__tests__/helpers.js +26 -0
- package/lib/client/registry/get-credentials.js +3 -9
- package/lib/client/registry/get-endpoint.js +29 -63
- package/lib/client/registry/get-fat-manifest.js +2 -9
- package/lib/client/registry/get-token.js +2 -13
- package/lib/client/registry/helpers.js +0 -4
- package/lib/config-provider.js +0 -12
- package/lib/config-providers/filesystem/__tests__/index.js +176 -0
- package/lib/config-providers/filesystem/index.js +5 -23
- package/lib/config-providers/npm/__tests__/index.js +226 -0
- package/lib/config-providers/npm/__tests__/util.js +1 -2
- package/lib/config-providers/npm/index.js +12 -35
- package/lib/config-providers/npm/util.js +0 -3
- package/lib/config.js +4 -19
- package/lib/domain/__tests__/container-image.js +81 -0
- package/lib/domain/__tests__/oci-api-specification.js +23 -0
- package/lib/domain/container-image.js +8 -21
- package/lib/domain/oci-api-specification.js +3 -5
- package/lib/driver-logging.js +0 -19
- package/lib/driver.js +0 -4
- package/lib/drivers/docker-compose/__tests__/client.js +249 -0
- package/lib/drivers/docker-compose/__tests__/index.js +430 -0
- package/lib/drivers/docker-compose/client.js +0 -16
- package/lib/drivers/docker-compose/index.js +7 -49
- package/lib/errors.js +0 -10
- package/lib/http-proxy.js +28 -23
- package/lib/index.js +1 -9
- package/lib/middleware/__tests__/add-service-proxy-config.js +258 -0
- package/lib/middleware/__tests__/develop.js +120 -0
- package/lib/middleware/__tests__/helpers.js +154 -0
- package/lib/middleware/__tests__/port-override.js +125 -0
- package/lib/middleware/__tests__/set-env-vars.js +94 -0
- package/lib/middleware/__tests__/set-image.js +76 -0
- package/lib/middleware/__tests__/set-logging-driver.js +94 -0
- package/lib/middleware/__tests__/tag-override.js +92 -0
- package/lib/middleware/add-service-proxy-config.js +8 -16
- package/lib/middleware/develop.js +2 -5
- package/lib/middleware/helpers.js +6 -12
- package/lib/middleware/port-override.js +5 -8
- package/lib/middleware/set-env-vars.js +6 -6
- package/lib/middleware/set-image.js +4 -5
- package/lib/middleware/set-logging-driver.js +6 -6
- package/lib/middleware/tag-override.js +4 -6
- package/lib/navy/__tests__/default-middleware.js +40 -0
- package/lib/navy/__tests__/index.js +1612 -0
- package/lib/navy/__tests__/middleware.js +71 -0
- package/lib/navy/__tests__/plugin-interface.js +121 -0
- package/lib/navy/__tests__/state.js +103 -0
- package/lib/navy/__tests__/util.js +24 -0
- package/lib/navy/default-middleware.js +0 -10
- package/lib/navy/index.js +83 -138
- package/lib/navy/middleware.js +0 -6
- package/lib/navy/plugin-interface.js +2 -10
- package/lib/navy/state.js +12 -24
- package/lib/navy/util.js +0 -1
- package/lib/service.js +2 -3
- package/lib/util/__tests__/exec-async.js +83 -0
- package/lib/util/__tests__/external-ip.js +97 -2
- package/lib/util/__tests__/get-lan-ip.js +46 -0
- package/lib/util/__tests__/has-update.js +136 -0
- package/lib/util/__tests__/https.js +301 -0
- package/lib/util/__tests__/navyrc.js +45 -0
- package/lib/util/__tests__/service-host.js +63 -5
- package/lib/util/__tests__/table.js +44 -0
- package/lib/util/docker-client.js +2 -10
- package/lib/util/exec-async.js +0 -4
- package/lib/util/external-ip.js +8 -12
- package/lib/util/fs.js +1 -6
- package/lib/util/get-lan-ip.js +0 -5
- package/lib/util/has-update.js +2 -14
- package/lib/util/https.js +11 -55
- package/lib/util/navyrc.js +0 -5
- package/lib/util/service-host.js +0 -17
- package/lib/util/table.js +0 -6
- package/package.json +14 -13
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
var _chai = require("chai");
|
|
5
|
+
var _sinon = _interopRequireDefault(require("sinon"));
|
|
6
|
+
var _proxyquire = _interopRequireDefault(require("proxyquire"));
|
|
7
|
+
var _errors = require("../../errors");
|
|
8
|
+
/* eslint-env mocha */
|
|
9
|
+
|
|
10
|
+
describe('cli/https', function () {
|
|
11
|
+
let sandbox;
|
|
12
|
+
let getNavyStub;
|
|
13
|
+
let navyStub;
|
|
14
|
+
let getConfigStub;
|
|
15
|
+
let getConfigDirStub;
|
|
16
|
+
let DEFAULT_TLS_ROOT_CA_DIR;
|
|
17
|
+
let reconfigureHTTPProxyStub;
|
|
18
|
+
let createCertStub;
|
|
19
|
+
let generateRootCaStub;
|
|
20
|
+
let removeCertStub;
|
|
21
|
+
let fsStub;
|
|
22
|
+
let consoleLogStub;
|
|
23
|
+
let httpsCli;
|
|
24
|
+
beforeEach(function () {
|
|
25
|
+
sandbox = _sinon.default.createSandbox();
|
|
26
|
+
navyStub = {
|
|
27
|
+
isInitialised: sandbox.stub().resolves(true),
|
|
28
|
+
getNavyFile: sandbox.stub().resolves({
|
|
29
|
+
ports: 'whatever'
|
|
30
|
+
}),
|
|
31
|
+
ensurePluginsLoaded: sandbox.stub().resolves(),
|
|
32
|
+
getAvailableServiceNames: sandbox.stub().resolves(['web', 'api']),
|
|
33
|
+
url: sandbox.stub().resolves('https://web.local')
|
|
34
|
+
};
|
|
35
|
+
getNavyStub = sandbox.stub().resolves(navyStub);
|
|
36
|
+
getConfigStub = sandbox.stub().returns({});
|
|
37
|
+
getConfigDirStub = sandbox.stub().returns('/cfg');
|
|
38
|
+
DEFAULT_TLS_ROOT_CA_DIR = '/default-ca-dir';
|
|
39
|
+
reconfigureHTTPProxyStub = sandbox.stub().resolves();
|
|
40
|
+
createCertStub = sandbox.stub().resolves();
|
|
41
|
+
generateRootCaStub = sandbox.stub().resolves();
|
|
42
|
+
removeCertStub = sandbox.stub().resolves();
|
|
43
|
+
fsStub = {
|
|
44
|
+
existsSync: sandbox.stub().returns(true),
|
|
45
|
+
readdirSync: sandbox.stub().returns(['web.local.crt', 'api.local.crt', 'something.txt'])
|
|
46
|
+
};
|
|
47
|
+
consoleLogStub = sandbox.stub(console, 'log');
|
|
48
|
+
httpsCli = _proxyquire.default.noCallThru()('../https', {
|
|
49
|
+
'../errors': {
|
|
50
|
+
NavyError: _errors.NavyError
|
|
51
|
+
},
|
|
52
|
+
'../navy': {
|
|
53
|
+
getNavy: getNavyStub
|
|
54
|
+
},
|
|
55
|
+
'../config': {
|
|
56
|
+
getConfig: getConfigStub,
|
|
57
|
+
getConfigDir: getConfigDirStub,
|
|
58
|
+
DEFAULT_TLS_ROOT_CA_DIR
|
|
59
|
+
},
|
|
60
|
+
'../http-proxy': {
|
|
61
|
+
reconfigureHTTPProxy: reconfigureHTTPProxyStub
|
|
62
|
+
},
|
|
63
|
+
'../util/https': {
|
|
64
|
+
createCert: createCertStub,
|
|
65
|
+
generateRootCa: generateRootCaStub,
|
|
66
|
+
removeCert: removeCertStub
|
|
67
|
+
},
|
|
68
|
+
fs: fsStub
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
afterEach(function () {
|
|
72
|
+
sandbox.restore();
|
|
73
|
+
});
|
|
74
|
+
describe('default export', function () {
|
|
75
|
+
describe('disable mode', function () {
|
|
76
|
+
it('should remove the cert and reconfigure the proxy', async function () {
|
|
77
|
+
await httpsCli([], {
|
|
78
|
+
navy: 'env-1',
|
|
79
|
+
disable: 'web'
|
|
80
|
+
});
|
|
81
|
+
(0, _chai.expect)(removeCertStub.calledOnce).to.equal(true);
|
|
82
|
+
(0, _chai.expect)(reconfigureHTTPProxyStub.calledOnce).to.equal(true);
|
|
83
|
+
(0, _chai.expect)(reconfigureHTTPProxyStub.firstCall.args[0].restart).to.equal(true);
|
|
84
|
+
});
|
|
85
|
+
it('should pass navyFile to reconfigureHTTPProxy when the navy is initialised', async function () {
|
|
86
|
+
navyStub.isInitialised.resolves(true);
|
|
87
|
+
navyStub.getNavyFile.resolves({
|
|
88
|
+
foo: 'bar'
|
|
89
|
+
});
|
|
90
|
+
await httpsCli([], {
|
|
91
|
+
navy: 'env-1',
|
|
92
|
+
disable: 'web'
|
|
93
|
+
});
|
|
94
|
+
(0, _chai.expect)(reconfigureHTTPProxyStub.firstCall.args[0].navyFile).to.eql({
|
|
95
|
+
foo: 'bar'
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
it('should pass undefined navyFile when the navy is not initialised', async function () {
|
|
99
|
+
navyStub.isInitialised.resolves(false);
|
|
100
|
+
await httpsCli([], {
|
|
101
|
+
navy: 'env-1',
|
|
102
|
+
disable: 'web'
|
|
103
|
+
});
|
|
104
|
+
(0, _chai.expect)(reconfigureHTTPProxyStub.firstCall.args[0].navyFile).to.equal(undefined);
|
|
105
|
+
(0, _chai.expect)(navyStub.getNavyFile.called).to.equal(false);
|
|
106
|
+
});
|
|
107
|
+
it('should print a confirmation message naming the disabled service', async function () {
|
|
108
|
+
await httpsCli([], {
|
|
109
|
+
navy: 'env-1',
|
|
110
|
+
disable: 'web'
|
|
111
|
+
});
|
|
112
|
+
const printed = consoleLogStub.getCalls().map(c => c.args[0] || '').join('\n');
|
|
113
|
+
(0, _chai.expect)(printed).to.contain('web');
|
|
114
|
+
(0, _chai.expect)(printed).to.contain('disabled');
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
describe('list mode (no services and no disable)', function () {
|
|
118
|
+
it('should return early when the certs path does not exist', async function () {
|
|
119
|
+
fsStub.existsSync.returns(false);
|
|
120
|
+
await httpsCli([], {
|
|
121
|
+
navy: 'env-1'
|
|
122
|
+
});
|
|
123
|
+
(0, _chai.expect)(fsStub.readdirSync.called).to.equal(false);
|
|
124
|
+
(0, _chai.expect)(generateRootCaStub.called).to.equal(false);
|
|
125
|
+
});
|
|
126
|
+
it('should print only .crt urls when listing', async function () {
|
|
127
|
+
fsStub.existsSync.callsFake(p => p === '/cfg/tls-certs');
|
|
128
|
+
await httpsCli([], {
|
|
129
|
+
navy: 'env-1'
|
|
130
|
+
});
|
|
131
|
+
const printed = consoleLogStub.getCalls().map(c => c.args[0] || '').join('\n');
|
|
132
|
+
(0, _chai.expect)(printed).to.contain('https://web.local');
|
|
133
|
+
(0, _chai.expect)(printed).to.contain('https://api.local');
|
|
134
|
+
(0, _chai.expect)(printed).to.not.contain('something.txt');
|
|
135
|
+
});
|
|
136
|
+
it('should also handle a null services arg as list mode', async function () {
|
|
137
|
+
fsStub.existsSync.returns(false);
|
|
138
|
+
await httpsCli(null, {
|
|
139
|
+
navy: 'env-1'
|
|
140
|
+
});
|
|
141
|
+
(0, _chai.expect)(generateRootCaStub.called).to.equal(false);
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
describe('enable mode', function () {
|
|
145
|
+
it('should generate the root CA when the CA cert/key are missing', async function () {
|
|
146
|
+
fsStub.existsSync.callsFake(p => !p.endsWith('ca.crt'));
|
|
147
|
+
await httpsCli(['web'], {
|
|
148
|
+
navy: 'env-1'
|
|
149
|
+
});
|
|
150
|
+
(0, _chai.expect)(generateRootCaStub.calledOnce).to.equal(true);
|
|
151
|
+
});
|
|
152
|
+
it('should skip generating the root CA when ca.crt and ca.key both exist', async function () {
|
|
153
|
+
fsStub.existsSync.returns(true);
|
|
154
|
+
await httpsCli(['web'], {
|
|
155
|
+
navy: 'env-1'
|
|
156
|
+
});
|
|
157
|
+
(0, _chai.expect)(generateRootCaStub.called).to.equal(false);
|
|
158
|
+
});
|
|
159
|
+
it('should create a cert for each available service', async function () {
|
|
160
|
+
await httpsCli(['web', 'api'], {
|
|
161
|
+
navy: 'env-1'
|
|
162
|
+
});
|
|
163
|
+
(0, _chai.expect)(createCertStub.callCount).to.equal(2);
|
|
164
|
+
});
|
|
165
|
+
it('should skip services that are not in the available service list', async function () {
|
|
166
|
+
await httpsCli(['web', 'unknown'], {
|
|
167
|
+
navy: 'env-1'
|
|
168
|
+
});
|
|
169
|
+
(0, _chai.expect)(createCertStub.callCount).to.equal(1);
|
|
170
|
+
const printed = consoleLogStub.getCalls().map(c => c.args[0] || '').join('\n');
|
|
171
|
+
(0, _chai.expect)(printed).to.contain('unknown');
|
|
172
|
+
(0, _chai.expect)(printed).to.contain('not found');
|
|
173
|
+
});
|
|
174
|
+
it('should rethrow as NavyError when createCert fails', async function () {
|
|
175
|
+
createCertStub.rejects(new Error('cert error'));
|
|
176
|
+
let caught;
|
|
177
|
+
try {
|
|
178
|
+
await httpsCli(['web'], {
|
|
179
|
+
navy: 'env-1'
|
|
180
|
+
});
|
|
181
|
+
} catch (err) {
|
|
182
|
+
caught = err;
|
|
183
|
+
}
|
|
184
|
+
(0, _chai.expect)(caught).to.be.instanceof(_errors.NavyError);
|
|
185
|
+
(0, _chai.expect)(caught.message).to.contain('Could not generate TLS cert');
|
|
186
|
+
});
|
|
187
|
+
it('should reconfigure HTTPS proxy after enabling and print services list', async function () {
|
|
188
|
+
await httpsCli(['web', 'api'], {
|
|
189
|
+
navy: 'env-1'
|
|
190
|
+
});
|
|
191
|
+
(0, _chai.expect)(reconfigureHTTPProxyStub.calledOnce).to.equal(true);
|
|
192
|
+
const printed = consoleLogStub.getCalls().map(c => c.args[0] || '').join('\n');
|
|
193
|
+
(0, _chai.expect)(printed).to.contain('web');
|
|
194
|
+
(0, _chai.expect)(printed).to.contain('api');
|
|
195
|
+
(0, _chai.expect)(printed).to.contain('HTTPS');
|
|
196
|
+
});
|
|
197
|
+
it('should use a custom tlsRootCaDir when set in config', async function () {
|
|
198
|
+
getConfigStub.returns({
|
|
199
|
+
tlsRootCaDir: '/custom-ca'
|
|
200
|
+
});
|
|
201
|
+
fsStub.existsSync.callsFake(p => p === '/custom-ca/ca.crt' || p === '/custom-ca/ca.key');
|
|
202
|
+
await httpsCli(['web'], {
|
|
203
|
+
navy: 'env-1'
|
|
204
|
+
});
|
|
205
|
+
const checkedPaths = fsStub.existsSync.getCalls().map(c => c.args[0]);
|
|
206
|
+
(0, _chai.expect)(checkedPaths.some(p => p === '/custom-ca/ca.crt')).to.equal(true);
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
});
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
var _chai = require("chai");
|
|
5
|
+
var _sinon = _interopRequireDefault(require("sinon"));
|
|
6
|
+
var _proxyquire = _interopRequireDefault(require("proxyquire"));
|
|
7
|
+
/* eslint-env mocha */
|
|
8
|
+
|
|
9
|
+
describe('cli/import', function () {
|
|
10
|
+
let sandbox;
|
|
11
|
+
let getNavyStub;
|
|
12
|
+
let navyStub;
|
|
13
|
+
let getImportOptionsForCLIStub;
|
|
14
|
+
let importNavyStub;
|
|
15
|
+
let fsStub;
|
|
16
|
+
let consoleLogStub;
|
|
17
|
+
let originalIsTTY;
|
|
18
|
+
let importCli;
|
|
19
|
+
beforeEach(function () {
|
|
20
|
+
sandbox = _sinon.default.createSandbox();
|
|
21
|
+
navyStub = {
|
|
22
|
+
name: 'env-1'
|
|
23
|
+
};
|
|
24
|
+
getNavyStub = sandbox.stub().returns(navyStub);
|
|
25
|
+
getImportOptionsForCLIStub = sandbox.stub().resolves({
|
|
26
|
+
configProvider: 'filesystem',
|
|
27
|
+
path: '/some/path'
|
|
28
|
+
});
|
|
29
|
+
importNavyStub = sandbox.stub().resolves();
|
|
30
|
+
fsStub = {
|
|
31
|
+
readFileSync: sandbox.stub().returns(' ___ \n /___\\ \n')
|
|
32
|
+
};
|
|
33
|
+
consoleLogStub = sandbox.stub(console, 'log');
|
|
34
|
+
originalIsTTY = process.stdout.isTTY;
|
|
35
|
+
process.stdout.isTTY = false;
|
|
36
|
+
importCli = _proxyquire.default.noCallThru()('../import', {
|
|
37
|
+
'../util/fs': fsStub,
|
|
38
|
+
'../': {
|
|
39
|
+
getNavy: getNavyStub
|
|
40
|
+
},
|
|
41
|
+
'../config-provider': {
|
|
42
|
+
getImportOptionsForCLI: getImportOptionsForCLIStub
|
|
43
|
+
},
|
|
44
|
+
'./util': {
|
|
45
|
+
importNavy: importNavyStub
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
afterEach(function () {
|
|
50
|
+
process.stdout.isTTY = originalIsTTY;
|
|
51
|
+
sandbox.restore();
|
|
52
|
+
});
|
|
53
|
+
describe('default export', function () {
|
|
54
|
+
it('should resolve the navy instance using opts.navy', async function () {
|
|
55
|
+
await importCli({
|
|
56
|
+
navy: 'env-1'
|
|
57
|
+
});
|
|
58
|
+
(0, _chai.expect)(getNavyStub.calledOnce).to.equal(true);
|
|
59
|
+
(0, _chai.expect)(getNavyStub.firstCall.args[0]).to.equal('env-1');
|
|
60
|
+
});
|
|
61
|
+
it('should read the sailing-boat ASCII art file', async function () {
|
|
62
|
+
await importCli({
|
|
63
|
+
navy: 'env-1'
|
|
64
|
+
});
|
|
65
|
+
(0, _chai.expect)(fsStub.readFileSync.calledOnce).to.equal(true);
|
|
66
|
+
(0, _chai.expect)(fsStub.readFileSync.firstCall.args[0]).to.contain('sailing-boat.txt');
|
|
67
|
+
});
|
|
68
|
+
it('should derive initialise opts via getImportOptionsForCLI and pass them to importNavy', async function () {
|
|
69
|
+
const opts = {
|
|
70
|
+
navy: 'env-1',
|
|
71
|
+
someOpt: 'value'
|
|
72
|
+
};
|
|
73
|
+
const initialiseOpts = {
|
|
74
|
+
configProvider: 'filesystem',
|
|
75
|
+
path: '/cwd'
|
|
76
|
+
};
|
|
77
|
+
getImportOptionsForCLIStub.resolves(initialiseOpts);
|
|
78
|
+
await importCli(opts);
|
|
79
|
+
(0, _chai.expect)(getImportOptionsForCLIStub.calledOnce).to.equal(true);
|
|
80
|
+
(0, _chai.expect)(getImportOptionsForCLIStub.firstCall.args[0]).to.equal(opts);
|
|
81
|
+
(0, _chai.expect)(importNavyStub.calledOnce).to.equal(true);
|
|
82
|
+
(0, _chai.expect)(importNavyStub.firstCall.args[0]).to.equal(navyStub);
|
|
83
|
+
(0, _chai.expect)(importNavyStub.firstCall.args[1]).to.equal(initialiseOpts);
|
|
84
|
+
});
|
|
85
|
+
it('should log the post-import help line', async function () {
|
|
86
|
+
await importCli({
|
|
87
|
+
navy: 'env-1'
|
|
88
|
+
});
|
|
89
|
+
const printed = consoleLogStub.getCalls().map(c => c.args[0] || '').join(' ');
|
|
90
|
+
(0, _chai.expect)(printed).to.contain('navy');
|
|
91
|
+
(0, _chai.expect)(printed).to.contain('any directory');
|
|
92
|
+
});
|
|
93
|
+
it('should not print the boat ASCII art when stdout is not a TTY', async function () {
|
|
94
|
+
process.stdout.isTTY = false;
|
|
95
|
+
await importCli({
|
|
96
|
+
navy: 'env-1'
|
|
97
|
+
});
|
|
98
|
+
const printed = consoleLogStub.getCalls().map(c => c.args[0] || '').join('\n');
|
|
99
|
+
(0, _chai.expect)(printed).to.not.contain('___');
|
|
100
|
+
});
|
|
101
|
+
it('should print the boat ASCII art when stdout is a TTY', async function () {
|
|
102
|
+
process.stdout.isTTY = true;
|
|
103
|
+
await importCli({
|
|
104
|
+
navy: 'env-1'
|
|
105
|
+
});
|
|
106
|
+
const printed = consoleLogStub.getCalls().map(c => c.args[0] || '').join('\n');
|
|
107
|
+
(0, _chai.expect)(printed).to.contain('___');
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
});
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
var _chai = require("chai");
|
|
5
|
+
var _sinon = _interopRequireDefault(require("sinon"));
|
|
6
|
+
var _proxyquire = _interopRequireDefault(require("proxyquire"));
|
|
7
|
+
var _errors = require("../../errors");
|
|
8
|
+
/* eslint-env mocha */
|
|
9
|
+
|
|
10
|
+
describe('cli/index', function () {
|
|
11
|
+
let sandbox;
|
|
12
|
+
let programStub;
|
|
13
|
+
let helpCmdStub;
|
|
14
|
+
let parseCalls;
|
|
15
|
+
let actionHandlerForHelp;
|
|
16
|
+
let originalArgv;
|
|
17
|
+
function loadModule({
|
|
18
|
+
args = ['placeholder'],
|
|
19
|
+
parseImpl
|
|
20
|
+
} = {}) {
|
|
21
|
+
actionHandlerForHelp = null;
|
|
22
|
+
parseCalls = [];
|
|
23
|
+
helpCmdStub = {
|
|
24
|
+
alias: sandbox.stub().returnsThis(),
|
|
25
|
+
action: sandbox.stub().callsFake(handler => {
|
|
26
|
+
actionHandlerForHelp = handler;
|
|
27
|
+
return helpCmdStub;
|
|
28
|
+
})
|
|
29
|
+
};
|
|
30
|
+
programStub = {
|
|
31
|
+
args,
|
|
32
|
+
version: sandbox.stub().returnsThis(),
|
|
33
|
+
command: sandbox.stub().returns(helpCmdStub),
|
|
34
|
+
help: sandbox.stub(),
|
|
35
|
+
parse: sandbox.stub().callsFake(argv => {
|
|
36
|
+
parseCalls.push(argv);
|
|
37
|
+
if (parseImpl) parseImpl();
|
|
38
|
+
})
|
|
39
|
+
};
|
|
40
|
+
return _proxyquire.default.noCallThru()('../index', {
|
|
41
|
+
'../../package.json': {
|
|
42
|
+
version: '1.2.3'
|
|
43
|
+
},
|
|
44
|
+
'./program': programStub,
|
|
45
|
+
'../errors': {
|
|
46
|
+
NavyError: _errors.NavyError
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
beforeEach(function () {
|
|
51
|
+
sandbox = _sinon.default.createSandbox();
|
|
52
|
+
sandbox.stub(console, 'log');
|
|
53
|
+
sandbox.stub(console, 'error');
|
|
54
|
+
originalArgv = process.argv;
|
|
55
|
+
});
|
|
56
|
+
afterEach(function () {
|
|
57
|
+
process.argv = originalArgv;
|
|
58
|
+
sandbox.restore();
|
|
59
|
+
});
|
|
60
|
+
describe('module side effects', function () {
|
|
61
|
+
it('should set the program version from package.json', function () {
|
|
62
|
+
loadModule();
|
|
63
|
+
(0, _chai.expect)(programStub.version.calledOnce).to.equal(true);
|
|
64
|
+
(0, _chai.expect)(programStub.version.firstCall.args[0]).to.equal('1.2.3');
|
|
65
|
+
});
|
|
66
|
+
it('should register a help command with * alias', function () {
|
|
67
|
+
loadModule();
|
|
68
|
+
(0, _chai.expect)(programStub.command.calledWith('help')).to.equal(true);
|
|
69
|
+
(0, _chai.expect)(helpCmdStub.alias.calledWith('*')).to.equal(true);
|
|
70
|
+
});
|
|
71
|
+
it('should call program.help() when invoking the help action', function () {
|
|
72
|
+
loadModule();
|
|
73
|
+
actionHandlerForHelp();
|
|
74
|
+
(0, _chai.expect)(programStub.help.called).to.equal(true);
|
|
75
|
+
});
|
|
76
|
+
it('should call program.parse with process.argv', function () {
|
|
77
|
+
loadModule();
|
|
78
|
+
(0, _chai.expect)(parseCalls).to.have.length(1);
|
|
79
|
+
(0, _chai.expect)(parseCalls[0]).to.equal(process.argv);
|
|
80
|
+
});
|
|
81
|
+
it('should call program.help when no args are present', function () {
|
|
82
|
+
loadModule({
|
|
83
|
+
args: []
|
|
84
|
+
});
|
|
85
|
+
(0, _chai.expect)(programStub.help.calledOnce).to.equal(true);
|
|
86
|
+
});
|
|
87
|
+
it('should not call program.help when args are present', function () {
|
|
88
|
+
loadModule({
|
|
89
|
+
args: ['some-cmd']
|
|
90
|
+
});
|
|
91
|
+
(0, _chai.expect)(programStub.help.called).to.equal(false);
|
|
92
|
+
});
|
|
93
|
+
it('should pretty-print a NavyError when parse throws one', function () {
|
|
94
|
+
const navyError = new _errors.NavyError('boom');
|
|
95
|
+
const prettyPrintStub = sandbox.stub(navyError, 'prettyPrint');
|
|
96
|
+
loadModule({
|
|
97
|
+
parseImpl: () => {
|
|
98
|
+
throw navyError;
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
(0, _chai.expect)(prettyPrintStub.calledOnce).to.equal(true);
|
|
102
|
+
});
|
|
103
|
+
it('should rethrow non-NavyError exceptions from parse', function () {
|
|
104
|
+
const otherError = new Error('boom');
|
|
105
|
+
let caught;
|
|
106
|
+
try {
|
|
107
|
+
loadModule({
|
|
108
|
+
parseImpl: () => {
|
|
109
|
+
throw otherError;
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
} catch (err) {
|
|
113
|
+
caught = err;
|
|
114
|
+
}
|
|
115
|
+
(0, _chai.expect)(caught).to.equal(otherError);
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
});
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
var _chai = require("chai");
|
|
5
|
+
var _sinon = _interopRequireDefault(require("sinon"));
|
|
6
|
+
var _proxyquire = _interopRequireDefault(require("proxyquire"));
|
|
7
|
+
/* eslint-env mocha */
|
|
8
|
+
|
|
9
|
+
describe('cli/lan-ip', function () {
|
|
10
|
+
let sandbox;
|
|
11
|
+
let getLANIPStub;
|
|
12
|
+
let setConfigStub;
|
|
13
|
+
let getConfigStub;
|
|
14
|
+
let reconfigureAllNaviesStub;
|
|
15
|
+
let consoleLogStub;
|
|
16
|
+
let lanIpCli;
|
|
17
|
+
beforeEach(function () {
|
|
18
|
+
sandbox = _sinon.default.createSandbox();
|
|
19
|
+
getLANIPStub = sandbox.stub();
|
|
20
|
+
setConfigStub = sandbox.stub().resolves();
|
|
21
|
+
getConfigStub = sandbox.stub();
|
|
22
|
+
reconfigureAllNaviesStub = sandbox.stub().resolves();
|
|
23
|
+
consoleLogStub = sandbox.stub(console, 'log');
|
|
24
|
+
lanIpCli = _proxyquire.default.noCallThru()('../lan-ip', {
|
|
25
|
+
'../util/get-lan-ip': {
|
|
26
|
+
getLANIP: getLANIPStub
|
|
27
|
+
},
|
|
28
|
+
'../config': {
|
|
29
|
+
setConfig: setConfigStub,
|
|
30
|
+
getConfig: getConfigStub
|
|
31
|
+
},
|
|
32
|
+
'./util/reconfigure': {
|
|
33
|
+
reconfigureAllNavies: reconfigureAllNaviesStub
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
afterEach(function () {
|
|
38
|
+
sandbox.restore();
|
|
39
|
+
});
|
|
40
|
+
describe('default export', function () {
|
|
41
|
+
it('should look up the LAN IP via getLANIP', async function () {
|
|
42
|
+
getLANIPStub.resolves('10.0.0.5');
|
|
43
|
+
getConfigStub.returns({
|
|
44
|
+
defaultNavy: 'dev'
|
|
45
|
+
});
|
|
46
|
+
await lanIpCli();
|
|
47
|
+
(0, _chai.expect)(getLANIPStub.calledOnce).to.equal(true);
|
|
48
|
+
});
|
|
49
|
+
it('should write a config that merges existing config with the new externalIP', async function () {
|
|
50
|
+
getLANIPStub.resolves('10.0.0.5');
|
|
51
|
+
getConfigStub.returns({
|
|
52
|
+
defaultNavy: 'dev',
|
|
53
|
+
tlsRootCaDir: '/ca'
|
|
54
|
+
});
|
|
55
|
+
await lanIpCli();
|
|
56
|
+
(0, _chai.expect)(setConfigStub.calledOnce).to.equal(true);
|
|
57
|
+
(0, _chai.expect)(setConfigStub.firstCall.args[0]).to.eql({
|
|
58
|
+
defaultNavy: 'dev',
|
|
59
|
+
tlsRootCaDir: '/ca',
|
|
60
|
+
externalIP: '10.0.0.5'
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
it('should override an existing externalIP in config with the LAN IP', async function () {
|
|
64
|
+
getLANIPStub.resolves('10.0.0.5');
|
|
65
|
+
getConfigStub.returns({
|
|
66
|
+
externalIP: 'old.host',
|
|
67
|
+
defaultNavy: 'dev'
|
|
68
|
+
});
|
|
69
|
+
await lanIpCli();
|
|
70
|
+
(0, _chai.expect)(setConfigStub.firstCall.args[0].externalIP).to.equal('10.0.0.5');
|
|
71
|
+
});
|
|
72
|
+
it('should reconfigure all navies after writing the new config', async function () {
|
|
73
|
+
getLANIPStub.resolves('10.0.0.5');
|
|
74
|
+
getConfigStub.returns({});
|
|
75
|
+
await lanIpCli();
|
|
76
|
+
(0, _chai.expect)(reconfigureAllNaviesStub.calledOnce).to.equal(true);
|
|
77
|
+
(0, _chai.expect)(setConfigStub.calledBefore(reconfigureAllNaviesStub)).to.equal(true);
|
|
78
|
+
});
|
|
79
|
+
it('should log a confirmation including the LAN IP', async function () {
|
|
80
|
+
getLANIPStub.resolves('10.0.0.5');
|
|
81
|
+
getConfigStub.returns({});
|
|
82
|
+
await lanIpCli();
|
|
83
|
+
const messages = consoleLogStub.getCalls().map(c => c.args[0] || '');
|
|
84
|
+
const hasLanIp = messages.some(m => typeof m === 'string' && m.includes('10.0.0.5'));
|
|
85
|
+
(0, _chai.expect)(hasLanIp).to.equal(true);
|
|
86
|
+
const hasLabel = messages.some(m => typeof m === 'string' && m.includes('LAN IP'));
|
|
87
|
+
(0, _chai.expect)(hasLabel).to.equal(true);
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
});
|