Skip to content

Commit ada386e

Browse files
committed
Made the tests pass and making them self-contained
1 parent 115d114 commit ada386e

File tree

11 files changed

+93
-65
lines changed

11 files changed

+93
-65
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@
1111
/testing.js
1212
/out
1313
/test.git
14+
/test/.reposCache

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,12 @@
3939
"devDependencies": {
4040
"nodeunit": "",
4141
"rimraf": "1.0.x",
42-
"ejs": "0.8.x"
42+
"ejs": "0.8.x",
43+
"ncp": "~0.4.2"
4344
},
4445
"scripts": {
4546
"install": "node install.js",
46-
"test": "cd test && nodeunit *.js",
47+
"test": "cd test && nodeunit nodegit.js",
4748
"gen": "node gen.js"
4849
}
4950
}

test/blob.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ var git = require('../'),
44
exports.content = function(test) {
55
var testOid = git.Oid.fromString('111dd657329797f6165f52f5085f61ac976dcf04');
66
test.expect(1);
7-
git.Repo.open(path.resolve('../.git'), function(err, repo) {
7+
git.Repo.open(path.resolve('repos/workdir/.git'), function(err, repo) {
88
repo.getBlob(testOid, function(err, blob) {
99
test.equals(blob.toString().slice(0, 7), "@import");
1010
test.done();

test/commit.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ var historyCountKnownSHA = 'fce88902e66c72b5b93e75bdb5ae717038b221f6';
66

77
exports.message = function(test) {
88
test.expect(2);
9-
git.Repo.open('../.git', function(error, repository) {
9+
git.Repo.open('repos/workdir/.git', function(error, repository) {
1010
repository.getCommit(historyCountKnownSHA, function(error, commit) {
1111
var message = commit.message();
1212
test.equals(error, null, 'There should be no error');
@@ -18,7 +18,7 @@ exports.message = function(test) {
1818

1919
exports.sha = function(test) {
2020
test.expect(2);
21-
git.Repo.open('../.git', function(error, repository) {
21+
git.Repo.open('repos/workdir/.git', function(error, repository) {
2222
repository.getCommit(historyCountKnownSHA, function(error, commit) {
2323
var sha = commit.sha();
2424
test.equals(error, null, 'There should be no error');
@@ -30,7 +30,7 @@ exports.sha = function(test) {
3030

3131
exports.time = function(test) {
3232
test.expect(2);
33-
git.Repo.open('../.git', function(error, repository) {
33+
git.Repo.open('repos/workdir/.git', function(error, repository) {
3434
repository.getCommit(historyCountKnownSHA, function(error, commit) {
3535
var time = commit.timeMs();
3636
test.equals(error, null, 'There should be no error');
@@ -42,7 +42,7 @@ exports.time = function(test) {
4242

4343
exports.date = function(test) {
4444
test.expect(2);
45-
git.Repo.open('../.git', function(error, repository) {
45+
git.Repo.open('repos/workdir/.git', function(error, repository) {
4646
repository.getCommit(historyCountKnownSHA, function(error, commit) {
4747
var date = commit.date();
4848
test.equals(error, null, 'There should be no error');
@@ -54,7 +54,7 @@ exports.date = function(test) {
5454

5555
exports.offset = function(test) {
5656
test.expect(2);
57-
git.Repo.open('../.git', function(error, repository) {
57+
git.Repo.open('repos/workdir/.git', function(error, repository) {
5858
repository.getCommit(historyCountKnownSHA, function(error, commit) {
5959
var offset = commit.offset();
6060
test.equals(error, null, 'There should be no error');
@@ -66,7 +66,7 @@ exports.offset = function(test) {
6666

6767
exports.author = function(test) {
6868
test.expect(2);
69-
git.Repo.open('../.git', function(error, repository) {
69+
git.Repo.open('repos/workdir/.git', function(error, repository) {
7070
repository.getCommit(historyCountKnownSHA, function(error, commit) {
7171
var author = commit.author();
7272
test.equals(error, null, 'There should be no error');
@@ -78,7 +78,7 @@ exports.author = function(test) {
7878

7979
exports.authorName = function(test) {
8080
test.expect(1);
81-
git.Repo.open('../.git', function(error, repository) {
81+
git.Repo.open('repos/workdir/.git', function(error, repository) {
8282
repository.getCommit(historyCountKnownSHA, function(error, commit) {
8383
var author = commit.author();
8484
var name = author.name();
@@ -90,7 +90,7 @@ exports.authorName = function(test) {
9090

9191
exports.authorEmail = function(test) {
9292
test.expect(1);
93-
git.Repo.open('../.git', function(error, repository) {
93+
git.Repo.open('repos/workdir/.git', function(error, repository) {
9494
repository.getCommit(historyCountKnownSHA, function(error, commit) {
9595
var author = commit.author();
9696
var email = author.email();
@@ -102,7 +102,7 @@ exports.authorEmail = function(test) {
102102

103103
exports.committerName = function(test) {
104104
test.expect(1);
105-
git.Repo.open('../.git', function(error, repository) {
105+
git.Repo.open('repos/workdir/.git', function(error, repository) {
106106
repository.getCommit(historyCountKnownSHA, function(error, commit) {
107107
var committer = commit.committer();
108108
var name = committer.name();
@@ -114,7 +114,7 @@ exports.committerName = function(test) {
114114

115115
exports.committerEmail = function(test) {
116116
test.expect(1);
117-
git.Repo.open('../.git', function(error, repository) {
117+
git.Repo.open('repos/workdir/.git', function(error, repository) {
118118
repository.getCommit(historyCountKnownSHA, function(error, commit) {
119119
var committer = commit.committer();
120120
var email = committer.email();
@@ -129,7 +129,7 @@ exports.committerEmail = function(test) {
129129
*/
130130
exports.improperCommitId = function(test) {
131131
test.expect(1);
132-
git.Repo.open('../.git', function(error, repository) {
132+
git.Repo.open('repos/workdir/.git', function(error, repository) {
133133
repository.getCommit('not a proper commit sha', function(error, commit) {
134134
test.notEqual(error, null, 'Error should occur');
135135
test.done();
@@ -142,7 +142,7 @@ exports.improperCommitId = function(test) {
142142
*/
143143
exports.history = function(test) {
144144
test.expect(4);
145-
git.Repo.open('../.git', function(error, repository) {
145+
git.Repo.open('repos/workdir/.git', function(error, repository) {
146146
repository.getCommit(historyCountKnownSHA, function(error, commit) {
147147
test.equals(null, error, 'Getting latest branch commit should not error');
148148
var historyCount = 0;
@@ -167,7 +167,7 @@ exports.history = function(test) {
167167
*/
168168
exports.masterHead = function(test) {
169169
test.expect(1);
170-
git.Repo.open('../.git', function(error, repository) {
170+
git.Repo.open('repos/workdir/.git', function(error, repository) {
171171
repository.getBranch('master', function(error, branch) {
172172
var sha = branch.sha();
173173
repository.getCommit(sha, function(error, commit) {
@@ -185,7 +185,7 @@ exports.masterHead = function(test) {
185185
*/
186186
exports.parents = function(test) {
187187
test.expect(3);
188-
git.Repo.open('../.git', function(error, repository) {
188+
git.Repo.open('repos/workdir/.git', function(error, repository) {
189189
repository.getCommit(historyCountKnownSHA, function(error, commit) {
190190
commit.getParents(function(error, parents) {
191191
test.equals(parents.length, 1, 'Commit should have exactly one parent');
@@ -203,7 +203,7 @@ exports.parents = function(test) {
203203
*/
204204
exports.tree = function(test) {
205205
test.expect(2);
206-
git.Repo.open('../.git', function(error, repository) {
206+
git.Repo.open('repos/workdir/.git', function(error, repository) {
207207
repository.getCommit(historyCountKnownSHA, function(error, commit) {
208208
test.equals(error, null, 'Getting latest branch commit should not error');
209209

@@ -226,7 +226,7 @@ exports.tree = function(test) {
226226
*/
227227
exports.getDiff = function(test) {
228228
test.expect(1);
229-
git.Repo.open('../.git', function(error, repository) {
229+
git.Repo.open('repos/workdir/.git', function(error, repository) {
230230
repository.getCommit(historyCountKnownSHA, function(error, commit) {
231231
commit.getDiff(function(error, diff) {
232232
test.equals(diff.length, 1, 'Should be one item in parents diff trees');

test/difflist.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ var historyCountKnownSHA = 'fce88902e66c72b5b93e75bdb5ae717038b221f6';
1111
*/
1212
exports.walkingDiffs = function(test) {
1313
test.expect(16);
14-
git.Repo.open('../.git', function(error, repository) {
14+
git.Repo.open('repos/workdir/.git', function(error, repository) {
1515
repository.getCommit(historyCountKnownSHA, function(error, commit) {
1616
commit.getDiff(function(error, diffList) {
1717
test.equal(null, error, 'Should not error');

test/nodegit.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
var fs = require('fs');
2+
var rimraf = require('rimraf');
3+
var ncp = require('ncp').ncp;
4+
var exec = require('child_process').exec;
5+
var path = require('path');
6+
var async = require('async');
7+
8+
var testFiles = ['blob','difflist','oid','repo','tree_entry','commit','reference','revwalk','tree'];
9+
10+
function setupReposCache(cb) {
11+
fs.mkdir('.reposCache',function() {
12+
async.series([
13+
function empty(cb) { exec('git init .reposCache/empty',cb); },
14+
function workdir(cb) { exec('git clone https://github.com/nodegit/nodegit.git .reposCache/workdir',cb); },
15+
function nonrepo(cb) {
16+
fs.mkdir('.reposCache/nonrepo',function() {
17+
fs.writeFile('.reposCache/nonrepo/file.txt','This is a bogus file',cb);
18+
});
19+
}
20+
],cb);
21+
});
22+
}
23+
24+
module.exports = {
25+
setUp: function(cb) {
26+
fs.exists('.reposCache',function(exists) {
27+
if (exists) {
28+
ncp('.reposCache','repos',cb);
29+
} else {
30+
setupReposCache(function(err) {
31+
if (err) { return cb(err); }
32+
ncp('.reposCache','repos',cb);
33+
});
34+
}
35+
});
36+
},
37+
tearDown: function(cb) {
38+
rimraf('repos',cb);
39+
}
40+
};
41+
42+
for(var i in testFiles) {
43+
var testFile = testFiles[i];
44+
module.exports[testFile] = require('./'+testFile);
45+
}

test/npm-debug.log

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

test/reference.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ var git = require('../'),
55
exports.lookup = function(test) {
66
test.expect(1);
77

8-
git.Repo.open('../.git', function(error, repo) {
8+
git.Repo.open('repos/workdir/.git', function(error, repo) {
99
repo.getReference('refs/heads/master', function(error, reference) {
1010
test.ok(reference instanceof git.Reference);
1111
test.done();

test/repo.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,23 @@ var git = require('../'),
77
* Ensure the repo method can handle opening repositories with async/sync
88
* signatures properly.
99
*/
10-
exports.open = function(test){
11-
test.expect(2);
10+
exports.openInvalidRepo = function(test){
11+
test.expect(1);
1212

1313
// Test invalid repository
14-
git.Repo.open('../templates', function(error, repository) {
15-
test.equals(error.message, "Could not find repository from '../templates'");
14+
git.Repo.open('repos/nonrepo', function(error, repository) {
15+
test.equals(error.message, "Could not find repository from 'repos/nonrepo'");
16+
test.done();
17+
});
18+
};
1619

17-
// Test valid repository
18-
git.Repo.open('../.git', function(error, repository) {
19-
test.equals(null, error, 'Valid repository error code');
20-
test.done();
21-
});
20+
exports.openValidRepo = function(test){
21+
test.expect(1);
22+
23+
// Test valid repository
24+
git.Repo.open('repos/workdir/.git', function(error, repository) {
25+
test.equals(null, error, 'Valid repository error code');
26+
test.done();
2227
});
2328
};
2429

@@ -40,18 +45,13 @@ exports.nonexistentDirectory = function(test) {
4045
*/
4146
exports.init = function(test) {
4247
test.expect(2);
43-
// Cleanup, remove test repo directory - if it exists
44-
rimraf('./test.git', function() {
45-
// Create bare repo and test for creation
46-
git.Repo.init('./test.git', true, function(error, path, isBare) {
47-
test.equals(null, error, 'Successfully created bare repository');
48-
// Verify repo exists
49-
git.Repo.open('./test.git', function(error, path, repo) {
50-
test.equals(null, error, 'Valid repository created');
51-
52-
// Cleanup, remove test repo directory
53-
rimraf('./test.git', test.done);
54-
});
48+
// Create bare repo and test for creation
49+
git.Repo.init('repos/newrepo', true, function(error, path, isBare) {
50+
test.equals(null, error, 'Successfully created bare repository');
51+
// Verify repo exists
52+
git.Repo.open('repos/newrepo', function(error, path, repo) {
53+
test.equals(null, error, 'Valid repository created');
54+
test.done();
5555
});
5656
});
5757
};

test/tree.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ var fileCount = 512; // Number of blob & blob executabless
88
exports.walk = function(test) {
99
test.expect(515);
1010

11-
git.Repo.open('../.git', function(error, repo) {
11+
git.Repo.open('repos/workdir/.git', function(error, repo) {
1212
repo.getCommit(sha, function(error, commit) {
1313
var entryCount = 0;
1414
commit.getTree(function(error, tree) {
@@ -29,8 +29,8 @@ exports.walk = function(test) {
2929
exports.insert = function(test) {
3030
test.expect(1);
3131

32-
git.Repo.open('../.git', function(error, repo) {
33-
repo.getCommit('1e7bc7fba93aabc8c76ebea41918f9ad892141ed', function(error, commit) {
32+
git.Repo.open('repos/workdir/.git', function(error, repo) {
33+
repo.getCommit(sha, function(error, commit) {
3434
commit.getTree(function(error, tree) {
3535
var text = "this is a file\n",
3636
buffer = new Buffer(text);

0 commit comments

Comments
 (0)