Permalink
Browse files

Finish updating tests for TreeEntry

  • Loading branch information...
1 parent 9e7b751 commit 6b727d77b85fb8818273bc8d1221e950de88b1b1 @tbranyen tbranyen committed Jul 11, 2014
Showing with 96 additions and 99 deletions.
  1. +9 −7 lib/tree_entry.js
  2. +8 −8 test/tests/commit.js
  3. +79 −0 test/tests/tree_entry.js
  4. +0 −84 test/tree_entry.js
View
16 lib/tree_entry.js
@@ -66,15 +66,17 @@ TreeEntry.prototype.sha = function() {
* @return {Tree}
*/
TreeEntry.prototype.getTree = function(callback) {
- var self = this;
- this.parent.repo.getTree(this.oid(), function(error, tree) {
- if (error) {
- return callback(error);
+ var entry = this;
+
+ return this.parent.repo.getTree(this.oid()).then(function(tree) {
+ tree.entry = entry;
+
+ if (callback) {
+ callback(null, tree);
}
- tree.entry = self;
- callback(null, tree);
- });
+ return tree;
+ }, callback);
};
/**
View
16 test/tests/commit.js
@@ -21,8 +21,8 @@ describe("Commit", function() {
});
it("will fail with an invalid sha", function() {
- return this.repository.getCommit("invalid").then(null, function(error) {
- assert.ok(error instanceof Error);
+ return this.repository.getCommit("invalid").then(null, function(err) {
+ assert.ok(err instanceof Error);
});
});
@@ -99,7 +99,7 @@ describe("Commit", function() {
done();
});
- history.on("error", function(error) {
+ history.on("error", function(err) {
assert.ok(false);
});
@@ -134,22 +134,22 @@ describe("Commit", function() {
var expectedCommitTreeEntryCount = 198;
this.commit.getTree().then(function(tree) {
- var walk = tree.walk();
+ var treeWalker = tree.walk();
- walk.on("entry", function(entry) {
+ treeWalker.on("entry", function(entry) {
commitTreeEntryCount++;
});
- walk.on("error", function() {
+ treeWalker.on("error", function() {
assert.ok(false);
});
- walk.on("end", function(error, entries) {
+ treeWalker.on("end", function(entries) {
assert.equal(commitTreeEntryCount, expectedCommitTreeEntryCount);
done();
});
- walk.start();
+ treeWalker.start();
});
});
View
79 test/tests/tree_entry.js
@@ -0,0 +1,79 @@
+var assert = require("assert");
+var path = require("path");
+
+describe("TreeEntry", function() {
+ var reposPath = path.resolve("test/repos/workdir/.git");
+ var oid = "5716e9757886eaf38d51c86b192258c960d9cfea";
+
+ var Repository = require("../../lib/repository");
+ var Tree = require("../../lib/tree");
+
+ beforeEach(function() {
+ var test = this;
+
+ return Repository.open(reposPath).then(function(repository) {
+ test.repository = repository;
+
+ return repository.getCommit(oid).then(function(commit) {
+ test.commit = commit;
+ });
+ });
+ });
+
+ it("will fail on a missing file", function() {
+ return this.commit.getEntry("test/-entry.js").then(null, function(err) {
+ assert.ok(err instanceof Error);
+ });
+ });
+
+ it("provides the correct sha for a file", function() {
+ return this.commit.getEntry("README.md").then(function(entry) {
+ var sha = entry.sha();
+
+ assert.equal(sha, "6cb45ba5d32532bf0d1310dc31ca4f20f59964bc");
+ });
+ });
+
+ it("provides the filename", function() {
+ return this.commit.getEntry("test/raw-commit.js").then(function(entry) {
+ var name = entry.name();
+
+ assert.equal(name, "raw-commit.js");
+ });
+ });
+
+ it("provides the blob representation of the entry", function() {
+ return this.commit.getEntry("test/raw-commit.js").then(function(entry) {
+ return entry.getBlob().then(function(blob) {
+ var size = blob.rawsize();
+
+ assert.equal(size, 2736);
+ });
+ });
+ });
+
+ it("provides the tree the entry is part of", function() {
+ return this.commit.getEntry("test").then(function(entry) {
+ return entry.getTree().then(function(tree) {
+ assert.ok(tree instanceof Tree);
+ });
+ });
+ });
+
+ it("can determine if an entry is a file", function() {
+ return this.commit.getEntry("README.md").then(function(entry) {
+ var isFile = entry.isFile();
+
+ assert.equal(isFile, true);
+ });
+ });
+
+ it("can determine if an entry is a directory", function() {
+ return this.commit.getEntry("example").then(function(entry) {
+ var isFile = entry.isFile();
+
+ assert.equal(isFile, false);
+ });
+ });
+});
+
View
84 test/tree_entry.js
@@ -1,84 +0,0 @@
-var git = require('../');
-
-var sha = '5716e9757886eaf38d51c86b192258c960d9cfea';
-
-var getEntry = function(path, callback) {
- git.Repo.open('repos/workdir/.git', function(error, repo) {
- repo.getCommit(sha, function(error, commit) {
- commit.getEntry(path, callback);
- });
- });
-};
-
-exports.missingFile = function(test) {
- test.expect(1);
-
- getEntry('test/convenience-entry.js', function(error, entry) {
- test.notEqual(error, null, 'Missing file should error');
- test.done();
- });
-};
-
-exports.sha = function(test) {
- test.expect(1);
- getEntry('README.md', function(error, entry) {
- var sha = entry.sha();
-
- test.equal(sha, '6cb45ba5d32532bf0d1310dc31ca4f20f59964bc', 'Entry SHA should match expected value');
- test.done();
- });
-};
-
-exports.isFile = function(test) {
- test.expect(2);
- getEntry('README.md', function(error, entry) {
- var isFile = entry.isFile();
- test.equal(isFile, true, 'Entry is a file');
- getEntry('example', function(error, entry) {
- var isFile = entry.isFile();
- test.equal(isFile, false, 'Entry is a directory');
- test.done();
- });
- });
-};
-
-exports.isDirectory = function(test) {
- test.expect(2);
- getEntry('example', function(error, entry) {
- test.equal(entry.isFile(), false, 'Entry is a directory');
- getEntry('README.md', function(error, entry) {
- test.equal(entry.isFile(), true, 'Entry is a file');
- test.done();
- });
- });
-};
-
-exports.name = function(test) {
- test.expect(2);
- getEntry('test/raw-commit.js', function(error, entry) {
- test.equal(error, null, 'Should not error');
- var name = entry.name();
- test.equal(name, 'raw-commit.js', 'Name should match expected value');
- test.done();
- });
-};
-
-exports.getBlob = function(test) {
- test.expect(1);
- getEntry('test/raw-commit.js', function(error, entry) {
- entry.getBlob(function(error, blob) {
- test.equal(blob.size(), 2736, 'Content length should match expected value');
- test.done();
- });
- });
-};
-
-exports.getTree = function(test) {
- test.expect(1);
- getEntry('test', function(error, entry) {
- entry.getTree(function(error, tree) {
- test.equal(tree instanceof git.Tree, true, 'Expected instance of Tree');
- test.done();
- });
- });
-};

0 comments on commit 6b727d7

Please sign in to comment.