Skip to content

Commit

Permalink
Big test cleanup.
Browse files Browse the repository at this point in the history
reference_bare_repo fixture is now just that - it's a reference repo
to test git data retrieval. There is now a helper method to create a
test repository, which will just make a duplicate of the
temp_repo_template in the /tmp directory, all write tests are now done
using these temp repos instead. They have a small set of test objects
to work with also.
  • Loading branch information
Sam Day committed Mar 30, 2011
1 parent 0af64ce commit 3e689f9
Show file tree
Hide file tree
Showing 20 changed files with 287 additions and 388 deletions.
3 changes: 2 additions & 1 deletion TODO.md
Expand Up @@ -9,4 +9,5 @@
* Implement ref packing method call, without breaking shit.
* Cache raw objects properly, so two requests for the same oid don't result in different objects.
* Maybe add convenience methods to all existing wrapped objects to get the raw object equivalent of them.
* Error handling in the EIO initialization stuff for objects. Not sure if something can go wrong there, but better safe than sorry.
* Error handling in the EIO initialization stuff for objects. Not sure if something can go wrong there, but better safe than sorry.
* Tests for initializing a new repository, bare or workingdir.
2 changes: 1 addition & 1 deletion src/repository.cc
Expand Up @@ -738,7 +738,7 @@ Handle<Value> Repository::GetTag(const Arguments& args) {
REQ_ARGS(1);
REQ_OID_ARG(0, oidArg);

if(args.Length() == 2) {
if(HAS_CALLBACK_ARG) {
ASYNC_PREPARE_GET_OID_OBJECT(Tag, git_tag);
}
else {
Expand Down
16 changes: 10 additions & 6 deletions test/blob.test.js
Expand Up @@ -30,18 +30,14 @@
helpers = require("./fixtures/helpers");

var repo = gitteh.openRepository(fixtureValues.REPO_PATH);
var tempRepo = helpers.createTestRepo();
var tempRepo = helpers.createTestRepo("blob");

vows.describe("Blob").addBatch({
teardown: function() {
helpers.cleanupTestRepo(tempRepo);
},

"Getting a blob *asynchronously*": {
topic: function() {
repo.getBlob(fixtureValues.TEST_BLOB, this.callback);
},

"gives us a Blob": function(blob) {
assert.isTrue(!!blob);
},
Expand Down Expand Up @@ -78,6 +74,10 @@ vows.describe("Blob").addBatch({

"with the correct id": function(blob) {
assert.equal(blob.id, helpers.getSHA1("blob 32\0Asynchronous blob creation test."));
},

"correct data": function(blob) {
assert.equal(blob.data.toString(), "Asynchronous blob creation test.");
}
},

Expand All @@ -94,6 +94,10 @@ vows.describe("Blob").addBatch({

"with the correct id": function(blob) {
assert.equal(blob.id, helpers.getSHA1("blob 31\0Synchronous blob creation test."));
},

"correct data": function(blob) {
assert.equal(blob.data.toString(), "Synchronous blob creation test.");
}
},

Expand Down
265 changes: 41 additions & 224 deletions test/commit.test.js
Expand Up @@ -30,6 +30,7 @@
helpers = require("./fixtures/helpers");

var repo = gitteh.openRepository(fixtureValues.REPO_PATH);
var tempRepo = helpers.createTestRepo("commit");

var createCommitTests = function(topic, commitFixture) {
var context = {
Expand Down Expand Up @@ -109,7 +110,7 @@ var createSyncCommitTests = function(commitFixture) {
};

vows.describe("Commit").addBatch({
/*"First commit (async)": createAsyncCommitTests(fixtureValues.FIRST_COMMIT),
"First commit (async)": createAsyncCommitTests(fixtureValues.FIRST_COMMIT),
"Second commit (async)": createAsyncCommitTests(fixtureValues.SECOND_COMMIT),
"Third commit (async)": createAsyncCommitTests(fixtureValues.THIRD_COMMIT),
"Fourth commit (async)": createAsyncCommitTests(fixtureValues.FOURTH_COMMIT),
Expand All @@ -119,254 +120,70 @@ vows.describe("Commit").addBatch({
"Second commit (sync)": createSyncCommitTests(fixtureValues.SECOND_COMMIT),
"Third commit (sync)": createSyncCommitTests(fixtureValues.THIRD_COMMIT),
"Fourth commit (sync)": createSyncCommitTests(fixtureValues.FOURTH_COMMIT),
"Fifth commit (sync)": createSyncCommitTests(fixtureValues.FIFTH_COMMIT),*/
}).addBatch({
startup: function() {
var gitRepo = helpers.createTestRepo();

var addRepoToAllTests = function(test) {
console.log(test);
if(test.context) test.context.repo = gitRepo;
test.context && test.context.tests && Object.keys(test.context.tests).forEach(function(testName) {

if(typeof(test.context.tests[testName]) == "object") {
addRepoToAllTests(test.context.tests[testName]);
}
});
};

addRepoToAllTests(this);
console.log(require("util").inspect(this, false, null));
},

teardown: function() {
console.log("teardown.");
this.context.gitRepo = helpers.cleanupTestRepo(this.context.gitRepo);
},
"Fifth commit (sync)": createSyncCommitTests(fixtureValues.FIFTH_COMMIT),

"Creating a new root commit *asynchronously*": {
topic: function() {
console.log("ME", this);
return "asdf";
var sig = {
name: "Sam",
email: "sam@test.com",
time: new Date()
time: new Date(1999, 1, 1)
};


console.log(require("util").inspect(this, false, null));
/*
this.context.gitRepo.createCommit({
tempRepo.createCommit({
message: "Test async commit.",
author: sig,
committer: sig,
tree: fixtureValues.FIRST_TREE.id
}, this.callback);*/
tree: tempRepo.TEST_TREE
}, this.callback);
},

"gives us the new commit": function(commit) {
console.log(commit);
}
}

/*
"Creating a new commit *synchronously*": {
topic: function() {
return repo.createCommit();
},
"gives us an identity Commit": function(commit) {
assert.isTrue(!!commit);
assert.isNull(commit.id);
assert.isNull(commit.message);
assert.isNull(commit.author);
assert.isNull(commit.committer);
assert.throws(function() {
commit.getTree();
}, Error);
},
},
"Creating a new commit *asynchronously*": {
topic: function() {
repo.createCommit(this.callback);
},
"gives us an identity Commit": function(commit) {
assert.isTrue(!!commit);
assert.isNull(commit.id);
assert.isNull(commit.message);
assert.isNull(commit.author);
assert.isNull(commit.committer);
assert.throws(function() {
commit.getTree();
}, Error);
}
},
"Getting commit tree *synchronously*": {
topic: function() {
var commit = repo.getCommit(fixtureValues.FIRST_COMMIT.id);
return commit.getTree();
},
"returns correct tree": function(tree) {
assert.isTrue(!!tree);
assert.equal(tree.id, fixtureValues.FIRST_TREE.id);
}
},
"Getting commit tree *asynchronously*": {
topic: function() {
var commit = repo.getCommit(fixtureValues.FIRST_COMMIT.id);
commit.getTree(this.callback);
},
"returns correct tree": function(tree) {
assert.isTrue(!!tree);
assert.equal(tree.id, fixtureValues.FIRST_TREE.id);
}
},
"Setting commit tree *asynchronously*": {
topic: function() {
var commit = this.context.commit = repo.createCommit();
var tree = this.context.tree = repo.getTree(fixtureValues.FIRST_TREE.id);
commit.setTree(tree, this.callback);
},
"sets tree correctly": function() {
assert.isTrue(this.context.tree === this.context.commit.getTree());
}
},
"Setting commit tree *synchronously*": {
topic: function() {
var commit = this.context.commit = repo.createCommit();
var tree = this.context.tree = repo.getTree(fixtureValues.FIRST_TREE.id);
commit.setTree(tree);
return true;
},
"sets tree correctly": function() {
assert.isTrue(this.context.tree === this.context.commit.getTree());
}
},
"Adding a parent commit *asynchronously*": {
topic: function() {
var commit = this.context.commit = repo.createCommit();
var parent = this.context.parent = repo.getCommit(fixtureValues.FIRST_COMMIT.id);
commit.addParent(parent, this.callback);
},

"adds parent correctly": function(res) {
assert.isTrue(res);
assert.isTrue(this.context.commit.getParent(0) === this.context.parent);
"with correct values": function(commit) {
assert.equal(commit.message, "Test async commit.");
assert.equal(commit.author.name, "Sam");
assert.equal(commit.author.email, "sam@test.com");
assert.equal(commit.author.time.getTime(), new Date(1999, 1, 1).getTime());
assert.equal(commit.committer.name, "Sam");
assert.equal(commit.committer.email, "sam@test.com");
assert.equal(commit.committer.time.getTime(), new Date(1999, 1, 1).getTime());
assert.equal(commit.tree, tempRepo.TEST_TREE);
}
},
"Adding a parent commit *synchronously*": {
topic: function() {
var commit = this.context.commit = repo.createCommit();
var parent = this.context.parent = repo.getCommit(fixtureValues.FIRST_COMMIT.id);

commit.addParent(parent);
return true;
},
"adds parent correctly": function() {
assert.isTrue(this.context.commit.getParent(0) === this.context.parent);
}
},
"Newly created commit": {
"Creating a new root commit *synchronously*": {
topic: function() {
return repo.createCommit();
},
"id is immutable": function(commit) {
commit.id = "foo";
assert.isNull(commit.id);
},
"saving the Commit gives us an error": function(commit) {
assert.throws(function() { commit.save(); }, Error);
},
},
"Saving a commit *synchronously*": {
topic: function(commit) {
var commit = repo.createCommit();
commit.message = "Test commit from Gitteh.";
commit.author = commit.committer = {
name: "Sam Day",
email: "sam.c.day@gmail.com",
time: new Date()
};
commit.setTree(repo.getTree(fixtureValues.FIRST_TREE.id));
this.context.commit = commit;
return function() {
commit.save();
};
},
"save works": function(fn) {
assert.doesNotThrow(fn, Error);
},
"commit object is not redundant": function() {
var commit = this.context.commit;
assert.isTrue(commit === repo.getCommit(commit.id));
}
},
"Saving a commit *asynchronously*": {
topic: function(commit) {
var commit = repo.createCommit();
commit.message = "Test async commit save from Gitteh.";
commit.author = commit.committer = {
name: "Sam Day",
email: "sam.c.day@gmail.com",
time: new Date()
var sig = {
name: "Sam",
email: "sam@test.com",
time: new Date(1999, 1, 1)
};
commit.setTree(repo.getTree(fixtureValues.FIRST_TREE.id));
this.context.commit = commit;
commit.save(this.callback);
},
"save works": function(res) {
assert.isTrue(res);
},
"commit object is not redundant": function() {
var commit = this.context.commit;
assert.isTrue(commit === repo.getCommit(commit.id));
}
},
"Creating a Commit and adding a parent by id": {
topic: function() {
repo.createCommit(this.callback);

return tempRepo.createCommit({
message: "Test sync commit.",
author: sig,
committer: sig,
tree: tempRepo.TEST_TREE
});
},

"works": function(commit) {
assert.doesNotThrow(function() {
commit.addParent(fixtureValues.FIRST_COMMIT.id);
}, Error);
assert.equal(commit.parentCount, 1);
"gives us the new commit": function(commit) {
assert.isTrue(!!commit);
},

"adds correctly": function(commit) {
assert.isTrue(commit.getParent(0) === repo.getCommit(fixtureValues.FIRST_COMMIT.id));
"with correct values": function(commit) {
assert.equal(commit.message, "Test sync commit.");
assert.equal(commit.author.name, "Sam");
assert.equal(commit.author.email, "sam@test.com");
assert.equal(commit.author.time.getTime(), new Date(1999, 1, 1).getTime());
assert.equal(commit.committer.name, "Sam");
assert.equal(commit.committer.email, "sam@test.com");
assert.equal(commit.committer.time.getTime(), new Date(1999, 1, 1).getTime());
assert.equal(commit.tree, tempRepo.TEST_TREE);
}
}*/
}
}).export(module);

0 comments on commit 3e689f9

Please sign in to comment.