Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Greatly improved looking tests
  • Loading branch information
tbranyen committed Jul 11, 2014
commit 6d77a5c99d543cc4b0320289a3c6699567bc3086
32 changes: 21 additions & 11 deletions lib/repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,16 @@ util.makeSafe(Repo.prototype, 'getReference');
* @return {Commit}
*/
Repo.prototype.getCommit = function(oid, callback) {
var self = this;
Commit.lookup(this, oid, function(error, commit) {
if (error) return callback(error);
commit.repo = self;
callback(null, commit);
var repository = this;

return Commit.lookup(repository, oid).then(function(commit) {
commit.repo = repository;

if (callback) {
callback(null, commit);
}

return commit;
});
};
util.normalizeOid(Repo.prototype, 'getCommit');
Expand All @@ -95,12 +100,17 @@ util.makeSafe(Repo.prototype, 'getCommit');
* @return {Blob}
*/
Repo.prototype.getBlob = function(oid, callback) {
var self = this;
Blob.lookup(this, oid, function(error, blob) {
if (error) return callback(error);
blob.repo = self;
callback(null, blob);
});
var repository= this;

return Blob.lookup(repository, oid).then(function(blob) {
blob.repo = repository;

if (callback) {
callback(null, blob);
}

return blob;
}, callback);
};
util.normalizeOid(Repo.prototype, 'getBlob');
util.makeSafe(Repo.prototype, 'getBlob');
Expand Down
4 changes: 2 additions & 2 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ exports.makeSafe = function(object, key) {
var oldFn = object[key];
object[key] = function() {
try {
oldFn.apply(this, arguments);
return oldFn.apply(this, arguments);
} catch (e) {
var callback = arguments[arguments.length - 1];
callback(e);
Expand All @@ -16,6 +16,6 @@ exports.normalizeOid = function(object, key) {
var oldFn = object[key];
object[key] = function(oid) {
if (typeof oid === 'string') oid = git.Oid.fromString(oid);
oldFn.apply(this, arguments);
return oldFn.apply(this, arguments);
};
};
18 changes: 10 additions & 8 deletions test/tests/blob.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@ describe("Blob", function() {
var Oid = nodegit.Oid;
var Repository = nodegit.Repository;

it("can fetch content from a commit", function(done) {
var oid= Oid.fromstr("111dd657329797f6165f52f5085f61ac976dcf04");
before(function() {
var test = this;

Repository.open(reposPath, function(err, repository) {
repository.getBlob(oid, function(err, blob) {
var contents = blob.toString();
return Repository.open(reposPath).then(function(repository) {
test.repository = repository;
});
});

assert.equal(contents.slice(0, 7), "@import");
it("can fetch content from a commit", function() {
var oid= Oid.fromstr("111dd657329797f6165f52f5085f61ac976dcf04");

done();
});
return this.repository.getBlob(oid).then(function(blob) {
assert.equal(blob.toString().slice(0, 7), "@import");
});
});
});
81 changes: 22 additions & 59 deletions test/tests/commit.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,77 +7,40 @@ var nodegit = require("../../");
var Repository = nodegit.Repository;

describe("Commit", function() {
var historyCountKnownSHA = "fce88902e66c72b5b93e75bdb5ae717038b221f6";
var reposPath = path.resolve("test/repos/workdir/.git");
var historyCountKnownSHA = "fce88902e66c72b5b93e75bdb5ae717038b221f6";

var Commit = require("./commit");

describe("when fetched", function() {

it("makes its message available", function(done) {
Repository.open(reposPath, function(error, repository) {
repository.getCommit(historyCountKnownSHA, function(error, commit) {
var message = commit.message();

assert.equal(error, null);
assert.equal(message, "Update README.md");

done();
});
});
});

it("makes its sha available", function(done) {
Repository.open(reposPath, function(error, repository) {
repository.getCommit(historyCountKnownSHA, function(error, commit) {
var sha = commit.sha();

assert.equal(error, null);
assert.equal(sha, historyCountKnownSHA);

done();
});
});
});

it("makes its time available", function(done) {
Repository.open(reposPath, function(error, repository) {
repository.getCommit(historyCountKnownSHA, function(error, commit) {
var time = commit.timeMs();
beforeEach(function() {
var test = this;

assert.equal(error, null);
assert.equal(time, 1362012884000);
return Repository.open(reposPath).then(function(repository) {
test.repository = repository;

done();
});
return repository.getCommit(historyCountKnownSHA).then(function(commit) {
test.commit = commit;
});
});
});

it("makes its date available", function(done) {
Repository.open(reposPath, function(error, repository) {
repository.getCommit(historyCountKnownSHA, function(error, commit) {
var date = commit.date();

assert.equal(error, null);
assert.equal(date.getTime(), 1362012884000);

done();
});
});
});
it("makes its message available", function() {
assert.equal(this.commit.message(), "Update README.md");
});

it("makes its offset available", function(done) {
Repository.open(reposPath, function(error, repository) {
repository.getCommit(historyCountKnownSHA, function(error, commit) {
var offset = commit.offset();
it("makes its sha available", function() {
assert.equal(this.commit.sha(), historyCountKnownSHA);
});

assert.equal(error, null);
assert.equal(offset, 780);
it("makes its time available", function() {
assert.equal(this.commit.timeMs(), 1362012884000);
});

done();
});
});
});
it("makes its date available", function() {
assert.equal(this.commit.date().getTime(), 1362012884000);
});

it("makes its offset available", function() {
assert.equal(this.commit.offset(), 780);
});
});
9 changes: 0 additions & 9 deletions test/tests/repository.js

This file was deleted.