|
| 1 | +var git = require( '../' ).raw, |
| 2 | + rimraf = require( '../vendor/rimraf' ); |
| 3 | + |
| 4 | +// Helper functions |
| 5 | +var helper = { |
| 6 | + // Test if obj is a true function |
| 7 | + testFunction: function( test, obj, label ) { |
| 8 | + // The object reports itself as a function |
| 9 | + test( typeof obj, 'function', label +' reports as a function.' ); |
| 10 | + // This ensures the repo is actually a derivative of the Function [[Class]] |
| 11 | + test( toString.call( obj ), '[object Function]', label +' [[Class]] is of type function.' ); |
| 12 | + }, |
| 13 | + // Test code and handle exception thrown |
| 14 | + testException: function( test, fun, label ) { |
| 15 | + try { |
| 16 | + fun(); |
| 17 | + test( false, label ); |
| 18 | + } |
| 19 | + catch (ex) { |
| 20 | + test( true, label ); |
| 21 | + } |
| 22 | + } |
| 23 | +}; |
| 24 | + |
| 25 | +// Ref |
| 26 | +exports.constructor = function( test ){ |
| 27 | + test.expect( 3 ); |
| 28 | + |
| 29 | + // Test for function |
| 30 | + helper.testFunction( test.equals, git.Ref, 'Ref' ); |
| 31 | + |
| 32 | + // Ensure we get an instance of Ref |
| 33 | + test.ok( new git.Ref() instanceof git.Ref, 'Invocation returns an instance of Ref' ); |
| 34 | + |
| 35 | + test.done(); |
| 36 | +}; |
| 37 | + |
| 38 | +// Ref::Lookup |
| 39 | +exports.lookup = function( test ) { |
| 40 | + var testRepo = new git.Repo(), |
| 41 | + master = new git.Ref(); |
| 42 | + |
| 43 | + test.expect( 5 ); |
| 44 | + |
| 45 | + // Test for function |
| 46 | + helper.testFunction( test.equals, master.lookup, 'Ref::Lookup' ); |
| 47 | + |
| 48 | + // Test repo argument existence |
| 49 | + helper.testException( test.ok, function() { |
| 50 | + master.lookup(); |
| 51 | + }, 'Throw an exception if no repo' ); |
| 52 | + |
| 53 | + // Test name argument existence |
| 54 | + helper.testException( test.ok, function() { |
| 55 | + master.lookup( testRepo ); |
| 56 | + }, 'Throw an exception if no name' ); |
| 57 | + |
| 58 | + // Test callback argument existence |
| 59 | + helper.testException( test.ok, function() { |
| 60 | + master.lookup( testRepo, 'refs/heads/master' ); |
| 61 | + }, 'Throw an exception if no callback' ); |
| 62 | + |
| 63 | + // Cleanup, remove test repo directory - if it exists |
| 64 | + rimraf( './test.git', function() { |
| 65 | + // // Create bare repo and test for creation |
| 66 | + // testRepo.init( './test.git', true, function( err, path, is_bare ) { |
| 67 | + // test.equals( 0, err, 'Successfully created bare repository' ); |
| 68 | + // // Verify repo exists |
| 69 | + // testRepo.open( './test.git', function(err, path) { |
| 70 | + // test.equals( 0, err, 'Valid repository created' ); |
| 71 | + // test.equals( true, is_bare, 'Returns valid is_bare value' ); |
| 72 | + |
| 73 | + // testRepo.free(); |
| 74 | + |
| 75 | + // // Cleanup, remove test repo directory |
| 76 | + // rimraf( './test.git', function() { |
| 77 | + test.done(); |
| 78 | + // }); |
| 79 | + // }); |
| 80 | + // }); |
| 81 | + }); |
| 82 | +}; |
0 commit comments