navy 7.0.0-alpha.4 → 7.0.0

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.
@@ -776,6 +776,148 @@ describe('navy/index', function () {
776
776
  (0, _chai.expect)(driver.destroy.calledOnce).to.equal(true);
777
777
  (0, _chai.expect)(deleteState.calledOnce).to.equal(true);
778
778
  });
779
+ it('should pass navyFile from a remaining navy when reconfiguring the proxy', async function () {
780
+ const driver = makeDriver();
781
+ const envPath = '/abs/env/Navyfile.js';
782
+ const otherPath = '/abs/other/Navyfile.js';
783
+ const destroyedNavyFile = {
784
+ httpProxyImage: 'destroyed/proxy:1'
785
+ };
786
+ const remainingNavyFile = {
787
+ httpProxyImage: 'remaining/proxy:1',
788
+ httpProxyEnv: {
789
+ FOO: 'bar'
790
+ }
791
+ };
792
+ const createProvider = path => ({
793
+ getNavyFilePath: async () => path
794
+ });
795
+ const resolveConfigProvider = _sinon.default.stub().callsFake(() => navy => createProvider(navy.normalisedName === 'other' ? otherPath : envPath));
796
+ const reconfigureHTTPProxy = _sinon.default.stub().resolves();
797
+ const deleteState = _sinon.default.stub().resolves();
798
+ const {
799
+ Navy
800
+ } = _proxyquire.default.noCallThru()('../', {
801
+ '../util/fs': {
802
+ readdirAsync: _sinon.default.stub().resolves(['env', 'other']),
803
+ lstatSync: _sinon.default.stub().returns({
804
+ isDirectory: () => true
805
+ })
806
+ },
807
+ './state': {
808
+ getState: _sinon.default.stub().resolves({
809
+ driver: 'docker-compose',
810
+ configProvider: 'filesystem'
811
+ }),
812
+ saveState: _sinon.default.stub().resolves(),
813
+ deleteState,
814
+ pathToNavys: _sinon.default.stub().returns('/home/test/.navy/navies'),
815
+ pathToNavy: _sinon.default.stub().callsFake(n => `/home/test/.navy/navies/${n}`)
816
+ },
817
+ '../driver': {
818
+ resolveDriverFromName: _sinon.default.stub().returns(() => driver)
819
+ },
820
+ '../config-provider': {
821
+ resolveConfigProviderFromName: resolveConfigProvider
822
+ },
823
+ '../config': {
824
+ getConfig: _sinon.default.stub().returns({
825
+ externalIP: null
826
+ })
827
+ },
828
+ './plugin-interface': {
829
+ loadPlugins: _sinon.default.stub().resolves([])
830
+ },
831
+ './middleware': {
832
+ middlewareRunner: _sinon.default.stub().resolves()
833
+ },
834
+ '../http-proxy': {
835
+ reconfigureHTTPProxy
836
+ },
837
+ '../util/external-ip': {
838
+ getExternalIP: _sinon.default.stub().resolves('127.0.0.1')
839
+ },
840
+ '../util/service-host': {
841
+ createUrlForService: _sinon.default.stub().resolves('http://svc.local'),
842
+ getUrlFromService: _sinon.default.stub().returns(null)
843
+ },
844
+ [envPath]: destroyedNavyFile,
845
+ [otherPath]: remainingNavyFile
846
+ });
847
+ await new Navy('env').destroy();
848
+ (0, _chai.expect)(reconfigureHTTPProxy.calledOnce).to.equal(true);
849
+ (0, _chai.expect)(reconfigureHTTPProxy.firstCall.args[0].navies).to.eql(['other']);
850
+ (0, _chai.expect)(reconfigureHTTPProxy.firstCall.args[0].navyFile).to.eql(remainingNavyFile);
851
+ });
852
+ it('should skip uninitialised remaining navies when resolving navyFile for the proxy', async function () {
853
+ const driver = makeDriver();
854
+ const otherPath = '/abs/other/Navyfile.js';
855
+ const remainingNavyFile = {
856
+ httpProxyImage: 'remaining/proxy:1'
857
+ };
858
+ const createProvider = path => ({
859
+ getNavyFilePath: async () => path
860
+ });
861
+ const resolveConfigProvider = _sinon.default.stub().callsFake(() => navy => createProvider(navy.normalisedName === 'other' ? otherPath : '/abs/env/Navyfile.js'));
862
+ const reconfigureHTTPProxy = _sinon.default.stub().resolves();
863
+ const deleteState = _sinon.default.stub().resolves();
864
+ const getState = _sinon.default.stub().callsFake(name => {
865
+ if (name === 'uninit') return Promise.resolve(null);
866
+ return Promise.resolve({
867
+ driver: 'docker-compose',
868
+ configProvider: 'filesystem'
869
+ });
870
+ });
871
+ const {
872
+ Navy
873
+ } = _proxyquire.default.noCallThru()('../', {
874
+ '../util/fs': {
875
+ readdirAsync: _sinon.default.stub().resolves(['env', 'uninit', 'other']),
876
+ lstatSync: _sinon.default.stub().returns({
877
+ isDirectory: () => true
878
+ })
879
+ },
880
+ './state': {
881
+ getState,
882
+ saveState: _sinon.default.stub().resolves(),
883
+ deleteState,
884
+ pathToNavys: _sinon.default.stub().returns('/home/test/.navy/navies'),
885
+ pathToNavy: _sinon.default.stub().callsFake(n => `/home/test/.navy/navies/${n}`)
886
+ },
887
+ '../driver': {
888
+ resolveDriverFromName: _sinon.default.stub().returns(() => driver)
889
+ },
890
+ '../config-provider': {
891
+ resolveConfigProviderFromName: resolveConfigProvider
892
+ },
893
+ '../config': {
894
+ getConfig: _sinon.default.stub().returns({
895
+ externalIP: null
896
+ })
897
+ },
898
+ './plugin-interface': {
899
+ loadPlugins: _sinon.default.stub().resolves([])
900
+ },
901
+ './middleware': {
902
+ middlewareRunner: _sinon.default.stub().resolves()
903
+ },
904
+ '../http-proxy': {
905
+ reconfigureHTTPProxy
906
+ },
907
+ '../util/external-ip': {
908
+ getExternalIP: _sinon.default.stub().resolves('127.0.0.1')
909
+ },
910
+ '../util/service-host': {
911
+ createUrlForService: _sinon.default.stub().resolves('http://svc.local'),
912
+ getUrlFromService: _sinon.default.stub().returns(null)
913
+ },
914
+ [otherPath]: remainingNavyFile
915
+ });
916
+ await new Navy('env').destroy();
917
+ (0, _chai.expect)(reconfigureHTTPProxy.calledOnce).to.equal(true);
918
+ (0, _chai.expect)(reconfigureHTTPProxy.firstCall.args[0].navies).to.eql(['uninit', 'other']);
919
+ (0, _chai.expect)(reconfigureHTTPProxy.firstCall.args[0].navyFile).to.eql(remainingNavyFile);
920
+ });
779
921
  it('should still delete state even when driver.destroy throws', async function () {
780
922
  const driver = makeDriver({
781
923
  destroy: _sinon.default.stub().rejects(new Error('boom'))
package/lib/navy/index.js CHANGED
@@ -237,9 +237,10 @@ class Navy extends _eventemitter.EventEmitter2 {
237
237
  if (!(await this.isInitialised())) {
238
238
  throw new _errors.NavyNotInitialisedError(this.name);
239
239
  }
240
+ const remainingNavyNames = (await getLaunchedNavyNames()).filter(navy => navy !== this.normalisedName);
240
241
  await (0, _httpProxy.reconfigureHTTPProxy)({
241
- navies: (await getLaunchedNavyNames()).filter(navy => navy !== this.normalisedName),
242
- navyFile: await this.getNavyFile()
242
+ navies: remainingNavyNames,
243
+ navyFile: await getNavyFileFromNavies(remainingNavyNames)
243
244
  });
244
245
  try {
245
246
  await (await this.safeGetDriver()).destroy();
@@ -499,6 +500,15 @@ function getNavy(navyName) {
499
500
  (0, _invariant.default)(navyName, "NO_NAVY_PROVIDED: No Navy provided");
500
501
  return new Navy(navyName);
501
502
  }
503
+ async function getNavyFileFromNavies(navyNames) {
504
+ for (const navyName of navyNames) {
505
+ const navy = getNavy(navyName);
506
+ if (!(await navy.isInitialised())) continue;
507
+ const navyFile = await navy.getNavyFile();
508
+ if (navyFile) return navyFile;
509
+ }
510
+ return null;
511
+ }
502
512
 
503
513
  /**
504
514
  * Returns an array of `Navy` instances which are currently imported and launched.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "navy",
3
- "version": "7.0.0-alpha.4",
3
+ "version": "7.0.0",
4
4
  "description": "Quick and powerful development environments using Docker and Docker Compose",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",