Skip to content

Commit 6b727d7

Browse files
committed
Finish updating tests for TreeEntry
1 parent 9e7b751 commit 6b727d7

4 files changed

Lines changed: 96 additions & 99 deletions

File tree

lib/tree_entry.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,17 @@ TreeEntry.prototype.sha = function() {
6666
* @return {Tree}
6767
*/
6868
TreeEntry.prototype.getTree = function(callback) {
69-
var self = this;
70-
this.parent.repo.getTree(this.oid(), function(error, tree) {
71-
if (error) {
72-
return callback(error);
69+
var entry = this;
70+
71+
return this.parent.repo.getTree(this.oid()).then(function(tree) {
72+
tree.entry = entry;
73+
74+
if (callback) {
75+
callback(null, tree);
7376
}
7477

75-
tree.entry = self;
76-
callback(null, tree);
77-
});
78+
return tree;
79+
}, callback);
7880
};
7981

8082
/**

test/tests/commit.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ describe("Commit", function() {
2121
});
2222

2323
it("will fail with an invalid sha", function() {
24-
return this.repository.getCommit("invalid").then(null, function(error) {
25-
assert.ok(error instanceof Error);
24+
return this.repository.getCommit("invalid").then(null, function(err) {
25+
assert.ok(err instanceof Error);
2626
});
2727
});
2828

@@ -99,7 +99,7 @@ describe("Commit", function() {
9999
done();
100100
});
101101

102-
history.on("error", function(error) {
102+
history.on("error", function(err) {
103103
assert.ok(false);
104104
});
105105

@@ -134,22 +134,22 @@ describe("Commit", function() {
134134
var expectedCommitTreeEntryCount = 198;
135135

136136
this.commit.getTree().then(function(tree) {
137-
var walk = tree.walk();
137+
var treeWalker = tree.walk();
138138

139-
walk.on("entry", function(entry) {
139+
treeWalker.on("entry", function(entry) {
140140
commitTreeEntryCount++;
141141
});
142142

143-
walk.on("error", function() {
143+
treeWalker.on("error", function() {
144144
assert.ok(false);
145145
});
146146

147-
walk.on("end", function(error, entries) {
147+
treeWalker.on("end", function(entries) {
148148
assert.equal(commitTreeEntryCount, expectedCommitTreeEntryCount);
149149
done();
150150
});
151151

152-
walk.start();
152+
treeWalker.start();
153153
});
154154
});
155155

test/tests/tree_entry.js

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
var assert = require("assert");
2+
var path = require("path");
3+
4+
describe("TreeEntry", function() {
5+
var reposPath = path.resolve("test/repos/workdir/.git");
6+
var oid = "5716e9757886eaf38d51c86b192258c960d9cfea";
7+
8+
var Repository = require("../../lib/repository");
9+
var Tree = require("../../lib/tree");
10+
11+
beforeEach(function() {
12+
var test = this;
13+
14+
return Repository.open(reposPath).then(function(repository) {
15+
test.repository = repository;
16+
17+
return repository.getCommit(oid).then(function(commit) {
18+
test.commit = commit;
19+
});
20+
});
21+
});
22+
23+
it("will fail on a missing file", function() {
24+
return this.commit.getEntry("test/-entry.js").then(null, function(err) {
25+
assert.ok(err instanceof Error);
26+
});
27+
});
28+
29+
it("provides the correct sha for a file", function() {
30+
return this.commit.getEntry("README.md").then(function(entry) {
31+
var sha = entry.sha();
32+
33+
assert.equal(sha, "6cb45ba5d32532bf0d1310dc31ca4f20f59964bc");
34+
});
35+
});
36+
37+
it("provides the filename", function() {
38+
return this.commit.getEntry("test/raw-commit.js").then(function(entry) {
39+
var name = entry.name();
40+
41+
assert.equal(name, "raw-commit.js");
42+
});
43+
});
44+
45+
it("provides the blob representation of the entry", function() {
46+
return this.commit.getEntry("test/raw-commit.js").then(function(entry) {
47+
return entry.getBlob().then(function(blob) {
48+
var size = blob.rawsize();
49+
50+
assert.equal(size, 2736);
51+
});
52+
});
53+
});
54+
55+
it("provides the tree the entry is part of", function() {
56+
return this.commit.getEntry("test").then(function(entry) {
57+
return entry.getTree().then(function(tree) {
58+
assert.ok(tree instanceof Tree);
59+
});
60+
});
61+
});
62+
63+
it("can determine if an entry is a file", function() {
64+
return this.commit.getEntry("README.md").then(function(entry) {
65+
var isFile = entry.isFile();
66+
67+
assert.equal(isFile, true);
68+
});
69+
});
70+
71+
it("can determine if an entry is a directory", function() {
72+
return this.commit.getEntry("example").then(function(entry) {
73+
var isFile = entry.isFile();
74+
75+
assert.equal(isFile, false);
76+
});
77+
});
78+
});
79+

test/tree_entry.js

Lines changed: 0 additions & 84 deletions
This file was deleted.

0 commit comments

Comments
 (0)