aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabe Hayes <[email protected]>2013-07-27 11:17:58 -0700
committerGabe Hayes <[email protected]>2013-07-27 11:17:58 -0700
commit6e8f7eb88a365894df8352caa826f2c3d8ff700d (patch)
tree81e999b0792fdb8f8db71e02b0e261e24363fd99
parentbc464dc1d8c9a0ecfac4aefb8f12dd24347b5732 (diff)
downloadnode-coveralls-6e8f7eb88a365894df8352caa826f2c3d8ff700d.tar.xz
node-coveralls-6e8f7eb88a365894df8352caa826f2c3d8ff700d.zip
tests for fetchGitData
-rw-r--r--lib/fetchGitData.js63
-rw-r--r--test/fetchGitData.js99
2 files changed, 136 insertions, 26 deletions
diff --git a/lib/fetchGitData.js b/lib/fetchGitData.js
index 5f3e582..a5a8eb8 100644
--- a/lib/fetchGitData.js
+++ b/lib/fetchGitData.js
@@ -2,31 +2,42 @@ var exec = require("exec-sync");
var fetchGitData = function(git) {
- var i,
- execGit = true,
- head = {
- "author_name": {
- "format": "'%aN'",
- "default": "Unknown Author"
- },
- "author_email": {
- "format": "'%ae'",
- "default": ""
- },
- "committer_name": {
- "format": "'%cN'",
- "default": "Unknown Committer"
- },
- "committer_email": {
- "format": "'%ce'",
- "default" :""
- },
- "message": {
- "format": "'%s'",
- "default": "Unknown Commit Message"
- }
- },
- remotes = {};
+ var i;
+ var execGit = true;
+ var head = {
+ "author_name": {
+ "format": "'%aN'",
+ "default": "Unknown Author"
+ },
+ "author_email": {
+ "format": "'%ae'",
+ "default": ""
+ },
+ "committer_name": {
+ "format": "'%cN'",
+ "default": "Unknown Committer"
+ },
+ "committer_email": {
+ "format": "'%ce'",
+ "default" :""
+ },
+ "message": {
+ "format": "'%s'",
+ "default": "Unknown Commit Message"
+ }
+ };
+ var remotes = {};
+
+ //-- Throw an error if no data is passed
+ if ('undefined' === typeof git) {
+ throw new Error('No options passed');
+
+ //-- Throw an error if no head or head.id is provided
+ } else if (!git.hasOwnProperty('head')) {
+ throw new Error('You must provide the head');
+ } else if (!git.head.hasOwnProperty('id')) {
+ throw new Error('You must provide the head.id');
+ }
function saveRemote(name, url, push) {
var key = name + "-" + url;
@@ -87,7 +98,7 @@ var fetchGitData = function(git) {
if (execGit) {
//-- Branch
- if ("" === git.branch.length) {
+ if ("" === git.branch) {
git.branch = exec("git branch").split("\n")[0].replace(/^\*\ /, "").trim();
}
diff --git a/test/fetchGitData.js b/test/fetchGitData.js
new file mode 100644
index 0000000..aa5e2b2
--- /dev/null
+++ b/test/fetchGitData.js
@@ -0,0 +1,99 @@
+var should = require('should');
+var git = require('../lib/fetchGitData');
+
+describe("fetchGitData", function(){
+ beforeEach(function(){
+ process.env = {};
+ });
+ it("should throw an error when no data is passed", function() {
+ git.should.throw(/No options passed/);
+ });
+ it("should throw an error if no head is provided", function() {
+ var fn = function() {
+ git({});
+ };
+ fn.should.throw(/You must provide the head/);
+ });
+ it("should throw an error if no head.id is provided", function() {
+ var fn = function() {
+ git({
+ head: {}
+ });
+ };
+ fn.should.throw(/You must provide the head.id/);
+ });
+ it("should return default values", function() {
+ var options = git({
+ head: {
+ id: "COMMIT_HASH"
+ }
+ });
+ options.should.eql({
+ "head": {
+ "id": "COMMIT_HASH",
+ "author_name": "Unknown Author",
+ "author_email": "",
+ "committer_name": "Unknown Committer",
+ "committer_email": "",
+ "message": "Unknown Commit Message"
+ },
+ "branch": "",
+ "remotes": []
+ });
+ });
+ it("should override default values", function() {
+ var options = git({
+ "head": {
+ "id": "COMMIT_HASH",
+ "author_name": "MY AUTHOR",
+ "author_email": "",
+ "committer_name": "MY COMMITTER",
+ "committer_email": "",
+ "message": "MY COMMIT MESSAGE"
+ },
+ "branch": "TEST",
+ "remotes": [
+ {
+ "name": "TEST",
+ "url": "test-url"
+ }
+ ]
+ });
+ options.should.eql({
+ "head": {
+ "id": "COMMIT_HASH",
+ "author_name": "MY AUTHOR",
+ "author_email": "",
+ "committer_name": "MY COMMITTER",
+ "committer_email": "",
+ "message": "MY COMMIT MESSAGE"
+ },
+ "branch": "TEST",
+ "remotes": [
+ {
+ "name": "TEST",
+ "url": "test-url"
+ }
+ ]
+ });
+ });
+ it("execute git commands when a valid commit hash is given", function() {
+ var options = git({
+ "head": {
+ "id": "5eaec7e76af0743f9764e617472ef434f283a195"
+ }
+ });
+ options.head.should.eql({
+ "id": "5eaec7e76af0743f9764e617472ef434f283a195",
+ "author_name": "cainus",
+ "author_email": "[email protected]",
+ "committer_name": "cainus",
+ "committer_email": "[email protected]",
+ "message": "first commit"
+ });
+ options.branch.should.equal("master");
+ options.should.have.property("remotes");
+ options.remotes.should.be.instanceof(Array);
+ options.remotes.length.should.be.above(0);
+ });
+});