summaryrefslogtreecommitdiffstats
path: root/test/git.js
diff options
context:
space:
mode:
authorSamy Pesse <samypesse@gmail.com>2016-02-11 17:10:59 +0100
committerSamy Pesse <samypesse@gmail.com>2016-02-11 17:10:59 +0100
commit7f9aa214a412f3d173ac52042bd7250aacda6143 (patch)
tree84a6d59d1c5baf185bb3357357bcfbdbf96bc80c /test/git.js
parent347a536a4e313dece2e12d0ba1ec6654ee729c85 (diff)
downloadgitbook-7f9aa214a412f3d173ac52042bd7250aacda6143.zip
gitbook-7f9aa214a412f3d173ac52042bd7250aacda6143.tar.gz
gitbook-7f9aa214a412f3d173ac52042bd7250aacda6143.tar.bz2
Cleaner module for managing git refs
Diffstat (limited to 'test/git.js')
-rw-r--r--test/git.js31
1 files changed, 22 insertions, 9 deletions
diff --git a/test/git.js b/test/git.js
index bad031b..8667b07 100644
--- a/test/git.js
+++ b/test/git.js
@@ -1,5 +1,8 @@
var should = require('should');
-var git = require('../lib/utils/git');
+var path = require('path');
+var os = require('os');
+
+var Git = require('../lib/utils/git');
describe('Git', function() {
@@ -7,27 +10,27 @@ describe('Git', function() {
it('should correctly validate git urls', function() {
// HTTPS
- git.isUrl('git+https://github.com/Hello/world.git').should.be.ok;
+ Git.isUrl('git+https://github.com/Hello/world.git').should.be.ok;
// SSH
- git.isUrl('git+git@github.com:GitbookIO/gitbook.git/directory/README.md#e1594cde2c32e4ff48f6c4eff3d3d461743d74e1').should.be.ok;
+ Git.isUrl('git+git@github.com:GitbookIO/gitbook.git/directory/README.md#e1594cde2c32e4ff48f6c4eff3d3d461743d74e1').should.be.ok;
// Non valid
- git.isUrl('https://github.com/Hello/world.git').should.not.be.ok;
- git.isUrl('README.md').should.not.be.ok;
+ Git.isUrl('https://github.com/Hello/world.git').should.not.be.ok;
+ Git.isUrl('README.md').should.not.be.ok;
});
it('should parse HTTPS urls', function() {
- var parts = git.parseUrl('git+https://gist.github.com/69ea4542e4c8967d2fa7.git/test.md');
+ var parts = Git.parseUrl('git+https://gist.github.com/69ea4542e4c8967d2fa7.git/test.md');
should.exist(parts);
parts.host.should.be.equal('https://gist.github.com/69ea4542e4c8967d2fa7.git');
- parts.ref.should.be.equal('master');
+ should(parts.ref).be.equal(null);
parts.filepath.should.be.equal('test.md');
});
it('should parse HTTPS urls with a reference', function() {
- var parts = git.parseUrl('git+https://gist.github.com/69ea4542e4c8967d2fa7.git/test.md#1.0.0');
+ var parts = Git.parseUrl('git+https://gist.github.com/69ea4542e4c8967d2fa7.git/test.md#1.0.0');
should.exist(parts);
parts.host.should.be.equal('https://gist.github.com/69ea4542e4c8967d2fa7.git');
@@ -36,7 +39,7 @@ describe('Git', function() {
});
it('should parse SSH urls', function() {
- var parts = git.parseUrl('git+git@github.com:GitbookIO/gitbook.git/directory/README.md#e1594cde2c32e4ff48f6c4eff3d3d461743d74e1');
+ var parts = Git.parseUrl('git+git@github.com:GitbookIO/gitbook.git/directory/README.md#e1594cde2c32e4ff48f6c4eff3d3d461743d74e1');
should.exist(parts);
parts.host.should.be.equal('git@github.com:GitbookIO/gitbook.git');
@@ -45,4 +48,14 @@ describe('Git', function() {
});
});
+ describe('Cloning and resolving', function() {
+ it('should clone an HTTPS url', function() {
+ var git = new Git(path.join(os.tmpdir(), 'test-git-'+Date.now()));
+ return git.resolve('git+https://gist.github.com/69ea4542e4c8967d2fa7.git/test.md')
+ .then(function(filename) {
+ path.extname(filename).should.equal('.md');
+ });
+ });
+ });
+
});