Permalink
Browse files

add tests, and cleanup code

  • Loading branch information...
1 parent 59f6656 commit 0f315c570db3f6120a6c683fc8e3e8e113ea1163 Justin Cooper committed Oct 4, 2012
Showing with 75 additions and 13 deletions.
  1. +0 −7 editor/helpers/fs_helper.js
  2. +2 −1 editor/helpers/request_helper.js
  3. +14 −5 test/fs_helper_test.js
  4. +59 −0 test/git_helper_test.js
@@ -94,13 +94,6 @@ exports.check_for_repository = function(repository, cb) {
});
};
-exports.open_file = function(temp_path, cb) {
- var file_path = path.resolve(__dirname + '/' + temp_path);
- fs.readFile(file_path, 'ascii', function(err,data){
- cb(data);
- });
-};
-
exports.open_image = function(temp_path, cb) {
var file_path = path.resolve(__dirname + '/../../' + temp_path);
@@ -20,6 +20,7 @@ exports.post_ssh_key = function(profile, cb) {
body: qs.stringify(params),
oauth:oauth
}, function (e, r, body) {
+ console.log(e);
console.log(r.statusCode);
console.log(body);
cb (e, body);
@@ -43,7 +44,7 @@ exports.list_repositories = function(profile, cb) {
oauth:oauth,
json: true
}, function (e, r, body) {
- //console.log(e);
+ console.log(e);
//console.log(r.statusCode);
//console.log(body);
cb (e, body);
View
@@ -1,12 +1,13 @@
var fs_helper = require('../editor/helpers/fs_helper'),
- fs = require('fs');
+ fs = require('fs'),
+ should = require('should');
describe('fs_helper', function() {
describe('ssh keys', function(){
before(function(){
try {
- fs.unlinkSync(process.env['HOME'] + '/.ssh/id_rsa_bitbucket');
- fs.unlinkSync(process.env['HOME'] + '/.ssh/id_rsa_bitbucket.pub');
+ fs.unlinkSync(process.env.HOME + '/.ssh/id_rsa_bitbucket');
+ fs.unlinkSync(process.env.HOME + '/.ssh/id_rsa_bitbucket.pub');
} catch(e) {
}
@@ -31,13 +32,21 @@ describe('fs_helper', function() {
describe('when the key exists', function(){
it('should be true', function(done){
fs_helper.has_ssh_key(function(exists) {
- console.log(exists);
exists.should.equal(true);
done();
});
});
});
+ });
-
+ describe('check_for_repository', function() {
+ //TODO: test positive case
+ it('repository should not exist', function(done) {
+ fs_helper.check_for_repository('false-repository', function(err, exists) {
+ should.not.exist(err);
+ exists.should.equal(false);
+ done();
+ });
+ });
});
});
View
@@ -0,0 +1,59 @@
+var git_helper = require('../editor/helpers/git_helper'),
+ fs = require('fs'),
+ path = require('path'),
+ should = require('should'),
+ rimraf = require('rimraf');
+
+describe('git_helper', function() {
+ describe('clone_repository', function(){
+ before(function(){
+ var repository_path = path.join(__dirname + "/../repositories", 'Adafruit-Raspberry-Pi-Python-Code');
+ rimraf.sync(repository_path);
+ });
+
+ describe('when the repository does not exist', function(){
+ it('should not fail', function(done){
+ var repository = 'git://github.com/adafruit/Adafruit-Raspberry-Pi-Python-Code.git';
+ git_helper.clone_repository(repository, function(err, message) {
+ should.not.exist(err);
+ message.should.include('Cloning into');
+ done();
+ });
+ });
+ });
+
+ describe('when the repository exists', function(){
+ it('should return an error', function(done){
+ var repository = 'git://github.com/adafruit/Adafruit-Raspberry-Pi-Python-Code.git';
+ git_helper.clone_repository(repository, function(err, message) {
+ should.exist(err);
+ should.not.exist(message);
+ err.should.include('already exists and is not an empty directory.');
+ done();
+ });
+ });
+ });
+ });
+
+ describe('validate_config', function() {
+ it('should be valid', function(done) {
+ git_helper.validate_config(function(is_valid) {
+ is_valid.should.be.true;
+ done();
+ });
+ });
+ });
+
+ describe('add', function() {
+ describe('when an empty file is added', function() {
+ //TODO: this test is failing...the add method does not return a valid error
+ it('should return an error', function(done) {
+ git_helper.add('Adafruit-Raspberry-Pi-Python-Code', '', function(err, message) {
+ console.log(err, message);
+ done();
+ });
+ });
+ });
+
+ });
+});

0 comments on commit 0f315c5

Please sign in to comment.