|
| 1 | +var git = require( '../' ).git2, |
| 2 | + rimraf = require( '../vendor/rimraf' ) || require( 'rimraf' ); |
| 3 | + |
| 4 | +var testRepo = new git.Repo(); |
| 5 | + |
| 6 | +// Helper functions |
| 7 | +var helper = { |
| 8 | + // Test if obj is a true function |
| 9 | + testFunction: function( test, obj, label ) { |
| 10 | + // The object reports itself as a function |
| 11 | + test( typeof obj, 'function', label +' reports as a function.' ); |
| 12 | + // This ensures the repo is actually a derivative of the Function [[Class]] |
| 13 | + test( toString.call( obj ), '[object Function]', label +' [[Class]] is of type function.' ); |
| 14 | + }, |
| 15 | + // Test code and handle exception thrown |
| 16 | + testException: function( test, fun, label ) { |
| 17 | + try { |
| 18 | + fun(); |
| 19 | + test( false, label ); |
| 20 | + } |
| 21 | + catch (ex) { |
| 22 | + test( true, label ); |
| 23 | + } |
| 24 | + } |
| 25 | +}; |
| 26 | + |
| 27 | +// Oid |
| 28 | +exports.constructor = function( test ){ |
| 29 | + test.expect( 3 ); |
| 30 | + |
| 31 | + // Test for function |
| 32 | + helper.testFunction( test.equals, git.Commit, 'Commit' ); |
| 33 | + |
| 34 | + // Ensure we get an instance of Oid |
| 35 | + test.ok( new git.Commit(testRepo) instanceof git.Commit, 'Invocation returns an instance of Commit' ); |
| 36 | + |
| 37 | + test.done(); |
| 38 | +}; |
| 39 | + |
| 40 | +// Oid::Mkstr |
| 41 | +exports.lookup = function( test ) { |
| 42 | + var testOid = new git.Oid(), |
| 43 | + testCommit = new git.Commit(testRepo); |
| 44 | + |
| 45 | + testOid.mkstr( 'cb09e99e91d41705197e0fb60823fdc7df776691' ); |
| 46 | + |
| 47 | + test.expect( 8 ); |
| 48 | + |
| 49 | + // Test for function |
| 50 | + helper.testFunction( test.equals, testCommit.lookup, 'Commit::Lookup' ); |
| 51 | + |
| 52 | + // Test repo argument existence |
| 53 | + helper.testException( test.ok, function() { |
| 54 | + testCommit.lookup(); |
| 55 | + }, 'Throw an exception if no repo' ); |
| 56 | + |
| 57 | + // Test oid argument existence |
| 58 | + helper.testException( test.ok, function() { |
| 59 | + testCommit.lookup( testRepo ); |
| 60 | + }, 'Throw an exception if no oid' ); |
| 61 | + |
| 62 | + // Test callback argument existence |
| 63 | + helper.testException( test.ok, function() { |
| 64 | + testCommit.lookup( testRepo, testOid ); |
| 65 | + }, 'Throw an exception if no callback' ); |
| 66 | + |
| 67 | + // Test that both arguments result correctly |
| 68 | + helper.testException( test.ifError, function() { |
| 69 | + testCommit.lookup( testRepo, testOid, function() {} ); |
| 70 | + }, 'No exception is thrown with proper arguments' ); |
| 71 | + |
| 72 | + testRepo.open( './dummyrepo/.git', function( err, path ) { |
| 73 | + // Test invalid commit |
| 74 | + testOid.mkstr( '100644' ); |
| 75 | + testCommit.lookup( testRepo, testOid, function( err, details ) { |
| 76 | + test.notEqual( 0, err, 'Not a valid commit' ); |
| 77 | + |
| 78 | + // Test valid commit |
| 79 | + testOid.mkstr( '978feacee2432e67051f2714ec7d28ad80e16908' ); |
| 80 | + testCommit.lookup( testRepo, testOid, function( err, details ) { |
| 81 | + test.equals( 0, err, 'Valid commit'); |
| 82 | + |
| 83 | + //test.equals( 'object', typeof details, 'Details is an object' ); |
| 84 | + |
| 85 | + //test.equals( 'string', typeof details.message, 'Details message is a String' ); |
| 86 | + //if(details.message) { |
| 87 | + // test.equals( 'initial commit', details.message.trim(), 'Details has correct message' ); |
| 88 | + //} |
| 89 | + |
| 90 | + testRepo.free(); |
| 91 | + |
| 92 | + test.done(); |
| 93 | + }); |
| 94 | + }); |
| 95 | + }); |
| 96 | +}; |
0 commit comments