|
1 | 1 | var git = require( 'nodegit2' ).git2, |
2 | 2 | rimraf = require( '../vendor/rimraf'); |
3 | 3 |
|
| 4 | +var testRepo = new git.Repo(); |
| 5 | + |
4 | 6 | // Helper functions |
5 | 7 | var helper = { |
6 | 8 | // Test if obj is a true function |
@@ -37,28 +39,47 @@ exports.constructor = function( test ){ |
37 | 39 |
|
38 | 40 | // Oid::Mkstr |
39 | 41 | exports.lookup = function( test ) { |
40 | | - var testCommit = new git.Commit(); |
| 42 | + var testOid = new git.Oid(), |
| 43 | + testCommit = new git.Commit(); |
41 | 44 |
|
42 | | - test.expect( 2 ); |
| 45 | + test.expect( 8 ); |
43 | 46 |
|
44 | 47 | // Test for function |
45 | 48 | helper.testFunction( test.equals, testCommit.lookup, 'Commit::Lookup' ); |
46 | 49 |
|
47 | | - // Test path argument existence |
48 | | -// helper.testException( test.ok, function() { |
49 | | -// testOid.mkstr(); |
50 | | -// }, 'Throw an exception if no hex String' ); |
51 | | -// |
52 | | -// // Test that both arguments result correctly |
53 | | -// helper.testException( test.ifError, function() { |
54 | | -// testOid.mkstr( "somestr" ); |
55 | | -// }, 'No exception is thrown with proper arguments' ); |
56 | | -// |
57 | | -// // Test invalid hex id string |
58 | | -// test.equals( -2, testOid.mkstr( '1392DLFJIOS' ), 'Invalid hex id String' ); |
59 | | -// |
60 | | -// // Test valid hex id string |
61 | | -// test.equals( 0, testOid.mkstr( '1810DFF58D8A660512D4832E740F692884338CCD' ), 'Valid hex id String' ); |
| 50 | + // Test repo argument existence |
| 51 | + helper.testException( test.ok, function() { |
| 52 | + testCommit.lookup(); |
| 53 | + }, 'Throw an exception if no repo' ); |
| 54 | + |
| 55 | + // Test oid argument existence |
| 56 | + helper.testException( test.ok, function() { |
| 57 | + testCommit.lookup( testRepo ); |
| 58 | + }, 'Throw an exception if no oid' ); |
62 | 59 |
|
63 | | - test.done(); |
| 60 | + // Test callback argument existence |
| 61 | + helper.testException( test.ok, function() { |
| 62 | + testCommit.lookup( testRepo, testOid ); |
| 63 | + }, 'Throw an exception if no callback' ); |
| 64 | + |
| 65 | + // Test that both arguments result correctly |
| 66 | + helper.testException( test.ifError, function() { |
| 67 | + testCommit.lookup( testRepo, testOid, function() {} ); |
| 68 | + }, 'No exception is thrown with proper arguments' ); |
| 69 | + |
| 70 | + testRepo.open( './dummyrepo/.git', function( err, path ) { |
| 71 | + // Test invalid commit |
| 72 | + testOid.mkstr( '100644' ); |
| 73 | + testCommit.lookup( testRepo, testOid, function( err ) { |
| 74 | + test.notEqual( 0, err, 'Not a valid commit'); |
| 75 | + |
| 76 | + // Test valid commit |
| 77 | + testOid.mkstr( '978feacee2432e67051f2714ec7d28ad80e16908' ); |
| 78 | + testCommit.lookup( testRepo, testOid, function( err ) { |
| 79 | + test.equals( 0, err, 'Valid commit'); |
| 80 | + |
| 81 | + test.done(); |
| 82 | + }); |
| 83 | + }); |
| 84 | + }); |
64 | 85 | }; |
0 commit comments