From 0c7b09c2379922d2619c1f948b95a1e7adba976d Mon Sep 17 00:00:00 2001 From: Kenneth Lee Date: Thu, 16 Jan 2014 19:18:27 +0000 Subject: [PATCH 1/4] created svn tests in resolver factory --- test/core/resolverFactory.js | 73 ++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/test/core/resolverFactory.js b/test/core/resolverFactory.js index 0f953fc3..ef59c5d3 100644 --- a/test/core/resolverFactory.js +++ b/test/core/resolverFactory.js @@ -339,6 +339,79 @@ describe('resolverFactory', function () { .done(); }); + it('should recognize svn remote endpoints correctly', function (next) { + var promise = Q.resolve(); + var endpoints; + + endpoints = { + // svn: + 'svn://hostname.com/user/project': 'http://hostname.com/user/project', + 'svn://hostname.com/user/project/': 'http://hostname.com/user/project', + + // svn@: + 'svn://svn@hostname.com:user/project': 'http://svn@hostname.com:user/project', + 'svn://svn@hostname.com:user/project/': 'http://svn@hostname.com:user/project', + + // svn+http + 'svn+http://hostname.com/project/blah': 'http://hostname.com/project/blah', + 'svn+http://hostname.com/project/blah/': 'http://hostname.com/project/blah', + 'svn+http://user@hostname.com/project/blah': 'http://user@hostname.com/project/blah', + 'svn+http://user@hostname.com/project/blah/': 'http://user@hostname.com/project/blah', + + // svn+https + 'svn+https://hostname.com/project/blah': 'https://hostname.com/project/blah', + 'svn+https://hostname.com/project/blah/': 'https://hostname.com/project/blah', + 'svn+https://user@hostname.com/project/blah': 'https://user@hostname.com/project/blah', + 'svn+https://user@hostname.com/project/blah/': 'https://user@hostname.com/project/blah', + + // svn+ssh + 'svn+ssh://hostname.com/project/blah': 'svn+ssh://hostname.com/project/blah', + 'svn+ssh://hostname.com/project/blah/': 'svn+ssh://hostname.com/project/blah', + 'svn+ssh://user@hostname.com/project/blah': 'svn+ssh://user@hostname.com/project/blah', + 'svn+ssh://user@hostname.com/project/blah/': 'svn+ssh://user@hostname.com/project/blah' + }; + + mout.object.forOwn(endpoints, function (value, key) { + // Test without name and target + promise = promise.then(function () { + return callFactory({ source: key }); + }) + .then(function (resolver) { + expect(resolver).to.be.a(resolvers.Svn); + expect(resolver).to.not.be(resolvers.GitHub); + expect(resolver.getSource()).to.equal(value); + expect(resolver.getTarget()).to.equal('*'); + }); + + // Test with target + promise = promise.then(function () { + return callFactory({ source: key, target: 'commit-ish' }); + }) + .then(function (resolver) { + expect(resolver).to.be.a(resolvers.Svn); + expect(resolver).to.not.be(resolvers.GitHub); + expect(resolver.getSource()).to.equal(value); + expect(resolver.getTarget()).to.equal('commit-ish'); + }); + + // Test with name + promise = promise.then(function () { + return callFactory({ name: 'foo', source: key }); + }) + .then(function (resolver) { + expect(resolver).to.be.a(resolvers.Svn); + expect(resolver).to.not.be(resolvers.GitHub); + expect(resolver.getSource()).to.equal(value); + expect(resolver.getName()).to.equal('foo'); + expect(resolver.getTarget()).to.equal('*'); + }); + }); + + promise + .then(next.bind(next, null)) + .done(); + }); + it('should recognize local fs files/folder endpoints correctly', function (next) { var promise = Q.resolve(); var endpoints; From 820834111b22e587a861296c9a44ef6371866a6c Mon Sep 17 00:00:00 2001 From: Kenneth Lee Date: Thu, 16 Jan 2014 19:35:52 +0000 Subject: [PATCH 2/4] fixed svn+xxxxx protocol --- lib/core/resolverFactory.js | 4 ++-- lib/core/resolvers/SvnResolver.js | 10 ++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/core/resolverFactory.js b/lib/core/resolverFactory.js index a605eec7..6cdf7535 100644 --- a/lib/core/resolverFactory.js +++ b/lib/core/resolverFactory.js @@ -45,8 +45,8 @@ function getConstructor(source, config, registryClient) { }); } - // SVN case: svn, svn+ssh - if (/^svn(\+ssh)?:\/\//i.test(source)) { + // SVN case: svn, svn+ssh, svn+http, svn+https + if (/^svn(\+(ssh|https?))?:\/\//i.test(source)) { return Q.fcall(function () { return [resolvers.Svn, source]; }); diff --git a/lib/core/resolvers/SvnResolver.js b/lib/core/resolvers/SvnResolver.js index 137d97a6..20e8f353 100644 --- a/lib/core/resolvers/SvnResolver.js +++ b/lib/core/resolvers/SvnResolver.js @@ -365,12 +365,10 @@ SvnResolver.clearRuntimeCache = function () { // source url cleaning utility function // reason: the constructor is not called when using commands such as "list" SvnResolver.sourceUrl = function (source) { - if (!mout.string.startsWith(source, 'http://')) { - // force use http urls - return source.replace('svn://', 'http://').replace(/\/+$/, ''); - } - - return source; + return source + .replace(/^svn\+(https?):\/\//i, '$1://') // Change svn+http or svn+https to http(s) + .replace('svn://', 'http://') // Change svn to http + .replace(/\/+$/, ''); // Remove trailing slashes }; SvnResolver._cache = { From d27c36c70c2edd41d5105e6cff89270d5b86ed26 Mon Sep 17 00:00:00 2001 From: Kenneth Lee Date: Thu, 16 Jan 2014 19:52:02 +0000 Subject: [PATCH 3/4] fixed the gitResolver tags and associated test --- test/core/resolvers/gitResolver.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/core/resolvers/gitResolver.js b/test/core/resolvers/gitResolver.js index b2ddcc32..92e477a3 100644 --- a/test/core/resolvers/gitResolver.js +++ b/test/core/resolvers/gitResolver.js @@ -1167,21 +1167,21 @@ describe('GitResolver', function () { describe('#tags', function () { afterEach(clearResolverRuntimeCache); - it('should resolve to an empty array if no tags are found', function (next) { + it('should resolve to an empty hash if no tags are found', function (next) { GitResolver.refs = function () { return Q.resolve([]); }; GitResolver.tags('foo') .then(function (tags) { - expect(tags).to.be.an('array'); - expect(tags).to.eql([]); + expect(tags).to.be.an('object'); + expect(tags).to.eql({}); next(); }) .done(); }); - it('should resolve to an array of tags', function (next) { + it('should resolve to an hash of tags', function (next) { GitResolver.refs = function () { return Q.resolve([ 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa refs/heads/master', From 53f563ec085e790c86529327030cfa1d9ac80294 Mon Sep 17 00:00:00 2001 From: Kenneth Lee Date: Thu, 16 Jan 2014 20:07:04 +0000 Subject: [PATCH 4/4] added svn+file for local file system checkouts --- lib/core/resolverFactory.js | 4 ++-- lib/core/resolvers/SvnResolver.js | 2 +- test/core/resolverFactory.js | 6 +++++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/core/resolverFactory.js b/lib/core/resolverFactory.js index 6cdf7535..2e01b017 100644 --- a/lib/core/resolverFactory.js +++ b/lib/core/resolverFactory.js @@ -45,8 +45,8 @@ function getConstructor(source, config, registryClient) { }); } - // SVN case: svn, svn+ssh, svn+http, svn+https - if (/^svn(\+(ssh|https?))?:\/\//i.test(source)) { + // SVN case: svn, svn+ssh, svn+http, svn+https, svn+file + if (/^svn(\+(ssh|https?|file))?:\/\//i.test(source)) { return Q.fcall(function () { return [resolvers.Svn, source]; }); diff --git a/lib/core/resolvers/SvnResolver.js b/lib/core/resolvers/SvnResolver.js index 20e8f353..bc484e10 100644 --- a/lib/core/resolvers/SvnResolver.js +++ b/lib/core/resolvers/SvnResolver.js @@ -366,7 +366,7 @@ SvnResolver.clearRuntimeCache = function () { // reason: the constructor is not called when using commands such as "list" SvnResolver.sourceUrl = function (source) { return source - .replace(/^svn\+(https?):\/\//i, '$1://') // Change svn+http or svn+https to http(s) + .replace(/^svn\+(https?|file):\/\//i, '$1://') // Change svn+http or svn+https or svn+file to http(s), file respectively .replace('svn://', 'http://') // Change svn to http .replace(/\/+$/, ''); // Remove trailing slashes }; diff --git a/test/core/resolverFactory.js b/test/core/resolverFactory.js index ef59c5d3..ee733ae3 100644 --- a/test/core/resolverFactory.js +++ b/test/core/resolverFactory.js @@ -368,7 +368,11 @@ describe('resolverFactory', function () { 'svn+ssh://hostname.com/project/blah': 'svn+ssh://hostname.com/project/blah', 'svn+ssh://hostname.com/project/blah/': 'svn+ssh://hostname.com/project/blah', 'svn+ssh://user@hostname.com/project/blah': 'svn+ssh://user@hostname.com/project/blah', - 'svn+ssh://user@hostname.com/project/blah/': 'svn+ssh://user@hostname.com/project/blah' + 'svn+ssh://user@hostname.com/project/blah/': 'svn+ssh://user@hostname.com/project/blah', + + // svn+file + 'svn+file:///project/blah': 'file:///project/blah', + 'svn+file:///project/blah/': 'file:///project/blah' }; mout.object.forOwn(endpoints, function (value, key) {