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.
Files changed (149) hide show
  1. package/lib/__tests__/config-provider.js +75 -0
  2. package/lib/__tests__/config.js +130 -0
  3. package/lib/__tests__/driver-logging.js +148 -0
  4. package/lib/__tests__/driver.js +19 -0
  5. package/lib/__tests__/errors.js +49 -0
  6. package/lib/__tests__/http-proxy.js +214 -0
  7. package/lib/__tests__/index.js +25 -0
  8. package/lib/__tests__/service.js +16 -0
  9. package/lib/cli/__tests__/develop.js +239 -0
  10. package/lib/cli/__tests__/external-ip.js +68 -0
  11. package/lib/cli/__tests__/health.js +257 -0
  12. package/lib/cli/__tests__/https.js +210 -0
  13. package/lib/cli/__tests__/import.js +110 -0
  14. package/lib/cli/__tests__/index.js +118 -0
  15. package/lib/cli/__tests__/lan-ip.js +90 -0
  16. package/lib/cli/__tests__/launch.js +179 -0
  17. package/lib/cli/__tests__/live.js +155 -0
  18. package/lib/cli/__tests__/local-ip.js +72 -0
  19. package/lib/cli/__tests__/logs.js +52 -0
  20. package/lib/cli/__tests__/open.js +65 -0
  21. package/lib/cli/__tests__/program.js +472 -0
  22. package/lib/cli/__tests__/ps.js +345 -0
  23. package/lib/cli/__tests__/refresh-config.js +95 -0
  24. package/lib/cli/__tests__/run.js +54 -0
  25. package/lib/cli/__tests__/status.js +204 -0
  26. package/lib/cli/__tests__/updates.js +243 -0
  27. package/lib/cli/__tests__/wait-for-healthy.js +134 -0
  28. package/lib/cli/config/__tests__/index.js +275 -0
  29. package/lib/cli/config/__tests__/wrapper.js +53 -0
  30. package/lib/cli/config/index.js +19 -37
  31. package/lib/cli/config/wrapper.js +0 -6
  32. package/lib/cli/develop.js +7 -21
  33. package/lib/cli/doctor/__tests__/clean-compose-files.js +78 -0
  34. package/lib/cli/doctor/__tests__/index.js +67 -0
  35. package/lib/cli/doctor/__tests__/invalid-compose-config.js +103 -0
  36. package/lib/cli/doctor/__tests__/invalid-state.js +83 -0
  37. package/lib/cli/doctor/__tests__/util.js +91 -0
  38. package/lib/cli/doctor/clean-compose-files.js +5 -13
  39. package/lib/cli/doctor/index.js +0 -12
  40. package/lib/cli/doctor/invalid-compose-config.js +0 -4
  41. package/lib/cli/doctor/invalid-state.js +0 -6
  42. package/lib/cli/doctor/util.js +0 -10
  43. package/lib/cli/external-ip.js +0 -4
  44. package/lib/cli/health.js +0 -12
  45. package/lib/cli/https.js +9 -25
  46. package/lib/cli/import.js +0 -12
  47. package/lib/cli/index.js +0 -9
  48. package/lib/cli/lan-ip.js +2 -8
  49. package/lib/cli/launch.js +0 -9
  50. package/lib/cli/live.js +6 -16
  51. package/lib/cli/local-ip.js +2 -7
  52. package/lib/cli/logs.js +0 -3
  53. package/lib/cli/open.js +2 -7
  54. package/lib/cli/program.js +73 -101
  55. package/lib/cli/ps.js +1 -21
  56. package/lib/cli/refresh-config.js +0 -7
  57. package/lib/cli/run.js +0 -3
  58. package/lib/cli/status.js +0 -11
  59. package/lib/cli/updates.js +0 -22
  60. package/lib/cli/util/__tests__/get-or-initialise-navy.js +66 -0
  61. package/lib/cli/util/__tests__/import.js +123 -0
  62. package/lib/cli/util/__tests__/index.js +17 -0
  63. package/lib/cli/util/__tests__/merge-action-options.js +47 -0
  64. package/lib/cli/util/__tests__/reconfigure.js +78 -0
  65. package/lib/cli/util/get-or-initialise-navy.js +0 -7
  66. package/lib/cli/util/import.js +0 -9
  67. package/lib/cli/util/index.js +0 -2
  68. package/lib/cli/util/merge-action-options.js +20 -0
  69. package/lib/cli/util/reconfigure.js +0 -4
  70. package/lib/cli/wait-for-healthy.js +0 -21
  71. package/lib/client/registry/__tests__/get-credentials.js +62 -0
  72. package/lib/client/registry/__tests__/get-endpoint.js +124 -0
  73. package/lib/client/registry/__tests__/get-fat-manifest.js +67 -0
  74. package/lib/client/registry/__tests__/get-token.js +66 -0
  75. package/lib/client/registry/__tests__/helpers.js +26 -0
  76. package/lib/client/registry/get-credentials.js +3 -9
  77. package/lib/client/registry/get-endpoint.js +29 -63
  78. package/lib/client/registry/get-fat-manifest.js +2 -9
  79. package/lib/client/registry/get-token.js +2 -13
  80. package/lib/client/registry/helpers.js +0 -4
  81. package/lib/config-provider.js +0 -12
  82. package/lib/config-providers/filesystem/__tests__/index.js +176 -0
  83. package/lib/config-providers/filesystem/index.js +5 -23
  84. package/lib/config-providers/npm/__tests__/index.js +226 -0
  85. package/lib/config-providers/npm/__tests__/util.js +1 -2
  86. package/lib/config-providers/npm/index.js +12 -35
  87. package/lib/config-providers/npm/util.js +0 -3
  88. package/lib/config.js +4 -19
  89. package/lib/domain/__tests__/container-image.js +81 -0
  90. package/lib/domain/__tests__/oci-api-specification.js +23 -0
  91. package/lib/domain/container-image.js +8 -21
  92. package/lib/domain/oci-api-specification.js +3 -5
  93. package/lib/driver-logging.js +0 -19
  94. package/lib/driver.js +0 -4
  95. package/lib/drivers/docker-compose/__tests__/client.js +249 -0
  96. package/lib/drivers/docker-compose/__tests__/index.js +430 -0
  97. package/lib/drivers/docker-compose/client.js +0 -16
  98. package/lib/drivers/docker-compose/index.js +7 -49
  99. package/lib/errors.js +0 -10
  100. package/lib/http-proxy.js +28 -23
  101. package/lib/index.js +1 -9
  102. package/lib/middleware/__tests__/add-service-proxy-config.js +258 -0
  103. package/lib/middleware/__tests__/develop.js +120 -0
  104. package/lib/middleware/__tests__/helpers.js +154 -0
  105. package/lib/middleware/__tests__/port-override.js +125 -0
  106. package/lib/middleware/__tests__/set-env-vars.js +94 -0
  107. package/lib/middleware/__tests__/set-image.js +76 -0
  108. package/lib/middleware/__tests__/set-logging-driver.js +94 -0
  109. package/lib/middleware/__tests__/tag-override.js +92 -0
  110. package/lib/middleware/add-service-proxy-config.js +8 -16
  111. package/lib/middleware/develop.js +2 -5
  112. package/lib/middleware/helpers.js +6 -12
  113. package/lib/middleware/port-override.js +5 -8
  114. package/lib/middleware/set-env-vars.js +6 -6
  115. package/lib/middleware/set-image.js +4 -5
  116. package/lib/middleware/set-logging-driver.js +6 -6
  117. package/lib/middleware/tag-override.js +4 -6
  118. package/lib/navy/__tests__/default-middleware.js +40 -0
  119. package/lib/navy/__tests__/index.js +1612 -0
  120. package/lib/navy/__tests__/middleware.js +71 -0
  121. package/lib/navy/__tests__/plugin-interface.js +121 -0
  122. package/lib/navy/__tests__/state.js +103 -0
  123. package/lib/navy/__tests__/util.js +24 -0
  124. package/lib/navy/default-middleware.js +0 -10
  125. package/lib/navy/index.js +83 -138
  126. package/lib/navy/middleware.js +0 -6
  127. package/lib/navy/plugin-interface.js +2 -10
  128. package/lib/navy/state.js +12 -24
  129. package/lib/navy/util.js +0 -1
  130. package/lib/service.js +2 -3
  131. package/lib/util/__tests__/exec-async.js +83 -0
  132. package/lib/util/__tests__/external-ip.js +97 -2
  133. package/lib/util/__tests__/get-lan-ip.js +46 -0
  134. package/lib/util/__tests__/has-update.js +136 -0
  135. package/lib/util/__tests__/https.js +301 -0
  136. package/lib/util/__tests__/navyrc.js +45 -0
  137. package/lib/util/__tests__/service-host.js +63 -5
  138. package/lib/util/__tests__/table.js +44 -0
  139. package/lib/util/docker-client.js +2 -10
  140. package/lib/util/exec-async.js +0 -4
  141. package/lib/util/external-ip.js +8 -12
  142. package/lib/util/fs.js +1 -6
  143. package/lib/util/get-lan-ip.js +0 -5
  144. package/lib/util/has-update.js +2 -14
  145. package/lib/util/https.js +11 -55
  146. package/lib/util/navyrc.js +0 -5
  147. package/lib/util/service-host.js +0 -17
  148. package/lib/util/table.js +0 -6
  149. package/package.json +14 -13
@@ -0,0 +1,179 @@
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/launch', function () {
10
+ let sandbox;
11
+ let inquirerStub;
12
+ let getOrInitialiseNavyStub;
13
+ let navyStub;
14
+ let startDriverLoggingStub;
15
+ let stopDriverLoggingStub;
16
+ let launchCli;
17
+ beforeEach(function () {
18
+ sandbox = _sinon.default.createSandbox();
19
+ navyStub = {
20
+ name: 'env-1',
21
+ ensurePluginsLoaded: sandbox.stub().resolves(),
22
+ getNavyFile: sandbox.stub().resolves(null),
23
+ getAvailableServiceNames: sandbox.stub().resolves(['web', 'api', 'db']),
24
+ getLaunchedServiceNames: sandbox.stub().resolves([]),
25
+ emitAsync: sandbox.stub().resolves(),
26
+ launch: sandbox.stub().resolves()
27
+ };
28
+ getOrInitialiseNavyStub = sandbox.stub().resolves(navyStub);
29
+ inquirerStub = {
30
+ prompt: sandbox.stub().resolves({
31
+ services: []
32
+ })
33
+ };
34
+ startDriverLoggingStub = sandbox.stub();
35
+ stopDriverLoggingStub = sandbox.stub();
36
+ launchCli = _proxyquire.default.noCallThru()('../launch', {
37
+ inquirer: inquirerStub,
38
+ './util': {
39
+ getOrInitialiseNavy: getOrInitialiseNavyStub
40
+ },
41
+ '../driver-logging': {
42
+ startDriverLogging: startDriverLoggingStub,
43
+ stopDriverLogging: stopDriverLoggingStub
44
+ }
45
+ });
46
+ });
47
+ afterEach(function () {
48
+ sandbox.restore();
49
+ });
50
+ describe('default export', function () {
51
+ it('should resolve the navy via getOrInitialiseNavy(opts.navy)', async function () {
52
+ await launchCli(['web'], {
53
+ navy: 'env-1'
54
+ });
55
+ (0, _chai.expect)(getOrInitialiseNavyStub.calledWith('env-1')).to.equal(true);
56
+ });
57
+ it('should launch services without prompting when services are provided', async function () {
58
+ await launchCli(['web', 'api'], {
59
+ navy: 'env-1'
60
+ });
61
+ (0, _chai.expect)(inquirerStub.prompt.called).to.equal(false);
62
+ (0, _chai.expect)(navyStub.launch.calledOnce).to.equal(true);
63
+ (0, _chai.expect)(navyStub.launch.firstCall.args[0]).to.eql(['web', 'api']);
64
+ });
65
+ it('should bracket launch with start/stopDriverLogging', async function () {
66
+ await launchCli(['web'], {
67
+ navy: 'env-1'
68
+ });
69
+ (0, _chai.expect)(startDriverLoggingStub.calledOnce).to.equal(true);
70
+ (0, _chai.expect)(stopDriverLoggingStub.calledOnce).to.equal(true);
71
+ (0, _chai.expect)(startDriverLoggingStub.calledBefore(navyStub.launch)).to.equal(true);
72
+ (0, _chai.expect)(navyStub.launch.calledBefore(stopDriverLoggingStub)).to.equal(true);
73
+ });
74
+ it('should emit cli.before.launch before launching', async function () {
75
+ await launchCli(['web'], {
76
+ navy: 'env-1'
77
+ });
78
+ (0, _chai.expect)(navyStub.emitAsync.calledOnce).to.equal(true);
79
+ (0, _chai.expect)(navyStub.emitAsync.firstCall.args[0]).to.equal('cli.before.launch');
80
+ (0, _chai.expect)(navyStub.emitAsync.calledBefore(navyStub.launch)).to.equal(true);
81
+ });
82
+ it('should prompt with inquirer when no services are provided', async function () {
83
+ inquirerStub.prompt.resolves({
84
+ services: ['web']
85
+ });
86
+ await launchCli([], {
87
+ navy: 'env-1'
88
+ });
89
+ (0, _chai.expect)(inquirerStub.prompt.calledOnce).to.equal(true);
90
+ const promptArgs = inquirerStub.prompt.firstCall.args[0];
91
+ (0, _chai.expect)(promptArgs[0].type).to.equal('checkbox');
92
+ (0, _chai.expect)(promptArgs[0].name).to.equal('services');
93
+ (0, _chai.expect)(promptArgs[0].choices.map(c => c.name)).to.have.members(['web', 'api', 'db']);
94
+ });
95
+ it('should pre-check services from launchedServiceNames when present', async function () {
96
+ navyStub.getLaunchedServiceNames.resolves(['api']);
97
+ inquirerStub.prompt.resolves({
98
+ services: []
99
+ });
100
+ await launchCli([], {
101
+ navy: 'env-1'
102
+ });
103
+ const choices = inquirerStub.prompt.firstCall.args[0][0].choices;
104
+ const apiChoice = choices.find(c => c.name === 'api');
105
+ const webChoice = choices.find(c => c.name === 'web');
106
+ (0, _chai.expect)(apiChoice.checked).to.equal(true);
107
+ (0, _chai.expect)(webChoice.checked).to.equal(false);
108
+ });
109
+ it('should pre-check services from navyFile.launchDefaults when nothing is launched', async function () {
110
+ navyStub.getNavyFile.resolves({
111
+ launchDefaults: ['web']
112
+ });
113
+ inquirerStub.prompt.resolves({
114
+ services: []
115
+ });
116
+ await launchCli([], {
117
+ navy: 'env-1'
118
+ });
119
+ const choices = inquirerStub.prompt.firstCall.args[0][0].choices;
120
+ const webChoice = choices.find(c => c.name === 'web');
121
+ (0, _chai.expect)(webChoice.checked).to.equal(true);
122
+ });
123
+ it('should fall back to no defaults when navyFile is null and nothing is launched', async function () {
124
+ navyStub.getNavyFile.resolves(null);
125
+ inquirerStub.prompt.resolves({
126
+ services: []
127
+ });
128
+ await launchCli([], {
129
+ navy: 'env-1'
130
+ });
131
+ const choices = inquirerStub.prompt.firstCall.args[0][0].choices;
132
+ choices.forEach(c => (0, _chai.expect)(c.checked).to.equal(false));
133
+ });
134
+ it('should fall back to empty defaults when navyFile lacks launchDefaults', async function () {
135
+ navyStub.getNavyFile.resolves({});
136
+ inquirerStub.prompt.resolves({
137
+ services: []
138
+ });
139
+ await launchCli([], {
140
+ navy: 'env-1'
141
+ });
142
+ const choices = inquirerStub.prompt.firstCall.args[0][0].choices;
143
+ choices.forEach(c => (0, _chai.expect)(c.checked).to.equal(false));
144
+ });
145
+ it('should return early without launching when the user selects no services', async function () {
146
+ inquirerStub.prompt.resolves({
147
+ services: []
148
+ });
149
+ await launchCli([], {
150
+ navy: 'env-1'
151
+ });
152
+ (0, _chai.expect)(navyStub.launch.called).to.equal(false);
153
+ (0, _chai.expect)(navyStub.emitAsync.called).to.equal(false);
154
+ (0, _chai.expect)(startDriverLoggingStub.called).to.equal(false);
155
+ (0, _chai.expect)(stopDriverLoggingStub.called).to.equal(false);
156
+ });
157
+ it('should launch with the services chosen via the interactive prompt', async function () {
158
+ inquirerStub.prompt.resolves({
159
+ services: ['db', 'web']
160
+ });
161
+ await launchCli([], {
162
+ navy: 'env-1'
163
+ });
164
+ (0, _chai.expect)(navyStub.launch.calledOnce).to.equal(true);
165
+ (0, _chai.expect)(navyStub.launch.firstCall.args[0]).to.eql(['db', 'web']);
166
+ });
167
+ it('should treat a null services arg as no selection and prompt', async function () {
168
+ inquirerStub.prompt.resolves({
169
+ services: ['web']
170
+ });
171
+ await launchCli(null, {
172
+ navy: 'env-1'
173
+ });
174
+ (0, _chai.expect)(inquirerStub.prompt.calledOnce).to.equal(true);
175
+ (0, _chai.expect)(navyStub.launch.calledOnce).to.equal(true);
176
+ (0, _chai.expect)(navyStub.launch.firstCall.args[0]).to.eql(['web']);
177
+ });
178
+ });
179
+ });
@@ -0,0 +1,155 @@
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/live', function () {
11
+ let sandbox;
12
+ let getNavyStub;
13
+ let navyStub;
14
+ let getNavyRcStub;
15
+ let consoleLogStub;
16
+ let originalCwd;
17
+ let liveCli;
18
+ beforeEach(function () {
19
+ sandbox = _sinon.default.createSandbox();
20
+ navyStub = {
21
+ name: 'env-1',
22
+ getState: sandbox.stub().resolves({
23
+ services: {
24
+ web: {
25
+ _develop: {
26
+ mounts: {},
27
+ command: 'x'
28
+ }
29
+ }
30
+ }
31
+ }),
32
+ saveState: sandbox.stub().resolves(),
33
+ kill: sandbox.stub().resolves(),
34
+ relaunch: sandbox.stub().resolves()
35
+ };
36
+ getNavyStub = sandbox.stub().returns(navyStub);
37
+ getNavyRcStub = sandbox.stub().resolves(null);
38
+ consoleLogStub = sandbox.stub(console, 'log');
39
+ originalCwd = process.cwd;
40
+ sandbox.stub(process, 'cwd').returns('/work');
41
+ liveCli = _proxyquire.default.noCallThru()('../live', {
42
+ '../': {
43
+ getNavy: getNavyStub
44
+ },
45
+ '../errors': {
46
+ NavyError: _errors.NavyError
47
+ },
48
+ '../util/navyrc': getNavyRcStub
49
+ });
50
+ });
51
+ afterEach(function () {
52
+ process.cwd = originalCwd;
53
+ sandbox.restore();
54
+ });
55
+ describe('default export', function () {
56
+ it('should throw NavyError when navyrc exists but services is missing', async function () {
57
+ getNavyRcStub.resolves({
58
+ services: undefined
59
+ });
60
+ let caught;
61
+ try {
62
+ await liveCli('web', {
63
+ navy: 'env-1'
64
+ });
65
+ } catch (err) {
66
+ caught = err;
67
+ }
68
+ (0, _chai.expect)(caught).to.be.instanceof(_errors.NavyError);
69
+ (0, _chai.expect)(caught.message).to.contain('No valid .navyrc');
70
+ });
71
+ it('should throw when navyrc lists multiple services and none specified', async function () {
72
+ getNavyRcStub.resolves({
73
+ services: ['web', 'api']
74
+ });
75
+ let caught;
76
+ try {
77
+ await liveCli(undefined, {
78
+ navy: 'env-1'
79
+ });
80
+ } catch (err) {
81
+ caught = err;
82
+ }
83
+ (0, _chai.expect)(caught).to.be.instanceof(_errors.NavyError);
84
+ (0, _chai.expect)(caught.message).to.contain('Multiple service mappings');
85
+ });
86
+ it('should infer the only service from a single-service navyrc', async function () {
87
+ getNavyRcStub.resolves({
88
+ services: ['only-svc']
89
+ });
90
+ navyStub.getState.resolves({
91
+ services: {
92
+ 'only-svc': {
93
+ _develop: {
94
+ mounts: {}
95
+ }
96
+ }
97
+ }
98
+ });
99
+ await liveCli(undefined, {
100
+ navy: 'env-1'
101
+ });
102
+ (0, _chai.expect)(navyStub.kill.calledWith(['only-svc'])).to.equal(true);
103
+ });
104
+ it('should log a "nothing to do" message when service is not in develop mode', async function () {
105
+ navyStub.getState.resolves({
106
+ services: {
107
+ web: {}
108
+ }
109
+ });
110
+ await liveCli('web', {
111
+ navy: 'env-1'
112
+ });
113
+ const printed = consoleLogStub.getCalls().map(c => c.args[0] || '').join('\n');
114
+ (0, _chai.expect)(printed).to.contain('Nothing to do');
115
+ (0, _chai.expect)(navyStub.kill.called).to.equal(false);
116
+ (0, _chai.expect)(navyStub.relaunch.called).to.equal(false);
117
+ });
118
+ it('should log "nothing to do" when state has no services key', async function () {
119
+ navyStub.getState.resolves({});
120
+ await liveCli('web', {
121
+ navy: 'env-1'
122
+ });
123
+ const printed = consoleLogStub.getCalls().map(c => c.args[0] || '').join('\n');
124
+ (0, _chai.expect)(printed).to.contain('Nothing to do');
125
+ });
126
+ it('should log "nothing to do" when state is null', async function () {
127
+ navyStub.getState.resolves(null);
128
+ await liveCli('web', {
129
+ navy: 'env-1'
130
+ });
131
+ const printed = consoleLogStub.getCalls().map(c => c.args[0] || '').join('\n');
132
+ (0, _chai.expect)(printed).to.contain('Nothing to do');
133
+ });
134
+ it('should clear _develop, kill, and relaunch when service is in develop mode', async function () {
135
+ await liveCli('web', {
136
+ navy: 'env-1'
137
+ });
138
+ (0, _chai.expect)(navyStub.saveState.calledOnce).to.equal(true);
139
+ const newState = navyStub.saveState.firstCall.args[0];
140
+ (0, _chai.expect)(newState.services.web._develop).to.equal(undefined);
141
+ (0, _chai.expect)(navyStub.kill.calledWith(['web'])).to.equal(true);
142
+ (0, _chai.expect)(navyStub.relaunch.calledOnce).to.equal(true);
143
+ (0, _chai.expect)(navyStub.relaunch.firstCall.args[0]).to.eql({
144
+ noDeps: true
145
+ });
146
+ });
147
+ it('should log a confirmation message after switching out of dev mode', async function () {
148
+ await liveCli('web', {
149
+ navy: 'env-1'
150
+ });
151
+ const printed = consoleLogStub.getCalls().map(c => c.args[0] || '').join('\n');
152
+ (0, _chai.expect)(printed).to.contain('no longer in development');
153
+ });
154
+ });
155
+ });
@@ -0,0 +1,72 @@
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/local-ip', function () {
10
+ let sandbox;
11
+ let setConfigStub;
12
+ let getConfigStub;
13
+ let reconfigureAllNaviesStub;
14
+ let consoleLogStub;
15
+ let localIpCli;
16
+ beforeEach(function () {
17
+ sandbox = _sinon.default.createSandbox();
18
+ setConfigStub = sandbox.stub().resolves();
19
+ getConfigStub = sandbox.stub();
20
+ reconfigureAllNaviesStub = sandbox.stub().resolves();
21
+ consoleLogStub = sandbox.stub(console, 'log');
22
+ localIpCli = _proxyquire.default.noCallThru()('../local-ip', {
23
+ '../config': {
24
+ setConfig: setConfigStub,
25
+ getConfig: getConfigStub
26
+ },
27
+ './util/reconfigure': {
28
+ reconfigureAllNavies: reconfigureAllNaviesStub
29
+ }
30
+ });
31
+ });
32
+ afterEach(function () {
33
+ sandbox.restore();
34
+ });
35
+ describe('default export', function () {
36
+ it('should write a config that merges existing config with externalIP=127.0.0.1', async function () {
37
+ getConfigStub.returns({
38
+ defaultNavy: 'dev',
39
+ tlsRootCaDir: '/ca'
40
+ });
41
+ await localIpCli();
42
+ (0, _chai.expect)(setConfigStub.calledOnce).to.equal(true);
43
+ (0, _chai.expect)(setConfigStub.firstCall.args[0]).to.eql({
44
+ defaultNavy: 'dev',
45
+ tlsRootCaDir: '/ca',
46
+ externalIP: '127.0.0.1'
47
+ });
48
+ });
49
+ it('should override an existing externalIP in config with 127.0.0.1', async function () {
50
+ getConfigStub.returns({
51
+ externalIP: 'remote.host'
52
+ });
53
+ await localIpCli();
54
+ (0, _chai.expect)(setConfigStub.firstCall.args[0].externalIP).to.equal('127.0.0.1');
55
+ });
56
+ it('should reconfigure all navies after writing the new config', async function () {
57
+ getConfigStub.returns({});
58
+ await localIpCli();
59
+ (0, _chai.expect)(reconfigureAllNaviesStub.calledOnce).to.equal(true);
60
+ (0, _chai.expect)(setConfigStub.calledBefore(reconfigureAllNaviesStub)).to.equal(true);
61
+ });
62
+ it('should log a confirmation including the local IP', async function () {
63
+ getConfigStub.returns({});
64
+ await localIpCli();
65
+ const messages = consoleLogStub.getCalls().map(c => c.args[0] || '');
66
+ const hasIp = messages.some(m => typeof m === 'string' && m.includes('127.0.0.1'));
67
+ (0, _chai.expect)(hasIp).to.equal(true);
68
+ const hasLabel = messages.some(m => typeof m === 'string' && m.includes('local IP'));
69
+ (0, _chai.expect)(hasLabel).to.equal(true);
70
+ });
71
+ });
72
+ });
@@ -0,0 +1,52 @@
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/logs', function () {
10
+ let sandbox;
11
+ let getNavyStub;
12
+ let navyStub;
13
+ let logs;
14
+ beforeEach(function () {
15
+ sandbox = _sinon.default.createSandbox();
16
+ navyStub = {
17
+ spawnLogStream: sandbox.stub().resolves()
18
+ };
19
+ getNavyStub = sandbox.stub().returns(navyStub);
20
+ logs = _proxyquire.default.noCallThru()('../logs', {
21
+ '../': {
22
+ getNavy: getNavyStub
23
+ }
24
+ });
25
+ });
26
+ afterEach(function () {
27
+ sandbox.restore();
28
+ });
29
+ describe('default export', function () {
30
+ it('should resolve the navy instance using opts.navy', async function () {
31
+ await logs(['api'], {
32
+ navy: 'env-1'
33
+ });
34
+ (0, _chai.expect)(getNavyStub.calledOnce).to.equal(true);
35
+ (0, _chai.expect)(getNavyStub.firstCall.args[0]).to.equal('env-1');
36
+ });
37
+ it('should call spawnLogStream with the supplied services array', async function () {
38
+ const services = ['api', 'web'];
39
+ await logs(services, {
40
+ navy: 'env-1'
41
+ });
42
+ (0, _chai.expect)(navyStub.spawnLogStream.calledOnce).to.equal(true);
43
+ (0, _chai.expect)(navyStub.spawnLogStream.firstCall.args[0]).to.equal(services);
44
+ });
45
+ it('should propagate empty service lists through to spawnLogStream', async function () {
46
+ await logs([], {
47
+ navy: 'env-1'
48
+ });
49
+ (0, _chai.expect)(navyStub.spawnLogStream.firstCall.args[0]).to.eql([]);
50
+ });
51
+ });
52
+ });
@@ -0,0 +1,65 @@
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/open', function () {
10
+ let sandbox;
11
+ let getNavyStub;
12
+ let navyStub;
13
+ let openStub;
14
+ let consoleLogStub;
15
+ let openCli;
16
+ beforeEach(function () {
17
+ sandbox = _sinon.default.createSandbox();
18
+ navyStub = {
19
+ url: sandbox.stub().resolves('http://service.local')
20
+ };
21
+ getNavyStub = sandbox.stub().returns(navyStub);
22
+ openStub = sandbox.stub();
23
+ consoleLogStub = sandbox.stub(console, 'log');
24
+ openCli = _proxyquire.default.noCallThru()('../open', {
25
+ open: openStub,
26
+ '../': {
27
+ getNavy: getNavyStub
28
+ }
29
+ });
30
+ });
31
+ afterEach(function () {
32
+ sandbox.restore();
33
+ });
34
+ describe('default export', function () {
35
+ it('should resolve the navy instance using opts.navy', async function () {
36
+ await openCli('api', {
37
+ navy: 'env-1'
38
+ });
39
+ (0, _chai.expect)(getNavyStub.calledOnce).to.equal(true);
40
+ (0, _chai.expect)(getNavyStub.firstCall.args[0]).to.equal('env-1');
41
+ });
42
+ it('should resolve the URL for the requested service via navy.url', async function () {
43
+ await openCli('api', {
44
+ navy: 'env-1'
45
+ });
46
+ (0, _chai.expect)(navyStub.url.calledOnce).to.equal(true);
47
+ (0, _chai.expect)(navyStub.url.firstCall.args[0]).to.equal('api');
48
+ });
49
+ it('should pass the resolved URL to the open package', async function () {
50
+ navyStub.url.resolves('http://my-service.test');
51
+ await openCli('api', {
52
+ navy: 'env-1'
53
+ });
54
+ (0, _chai.expect)(openStub.calledOnce).to.equal(true);
55
+ (0, _chai.expect)(openStub.firstCall.args[0]).to.equal('http://my-service.test');
56
+ });
57
+ it('should log a message indicating which service is being opened', async function () {
58
+ await openCli('api', {
59
+ navy: 'env-1'
60
+ });
61
+ (0, _chai.expect)(consoleLogStub.calledOnce).to.equal(true);
62
+ (0, _chai.expect)(consoleLogStub.firstCall.args[0]).to.contain('Opening api...');
63
+ });
64
+ });
65
+ });