forked from nodegit/nodegit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathraw-repo.js
More file actions
129 lines (102 loc) · 3.41 KB
/
Copy pathraw-repo.js
File metadata and controls
129 lines (102 loc) · 3.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
var git = require( '../' ).raw,
rimraf = require( '../vendor/rimraf' ) || require( 'rimraf' ),
path = require( 'path' ),
fs = require( 'fs' );
// Helper functions
var helper = {
// Test if obj is a true function
testFunction: function( test, obj, label ) {
// The object reports itself as a function
test( typeof obj, 'function', label +' reports as a function.' );
// This ensures the repo is actually a derivative of the Function [[Class]]
test( toString.call( obj ), '[object Function]', label +' [[Class]] is of type function.' );
},
// Test code and handle exception thrown
testException: function( test, fun, label ) {
try {
fun();
test( false, label );
}
catch (ex) {
test( true, label );
}
}
};
// Repo
exports.constructor = function( test ){
test.expect( 3 );
// Test for function
helper.testFunction( test.equals, git.Repo, 'Repo' );
// Ensure we get an instance of Repo
test.ok( new git.Repo() instanceof git.Repo, 'Invocation returns an instance of Repo' );
test.done();
};
// Repo::Open
exports.open = function( test ) {
var testRepo = new git.Repo();
test.expect( 6 );
// Test for function
helper.testFunction( test.equals, testRepo.open, 'Repo::Open' );
// Test path argument existence
helper.testException( test.ok, function() {
testRepo.open();
}, 'Throw an exception if no path' );
// Test callback argument existence
helper.testException( test.ok, function() {
testRepo.open( "some/path" );
}, 'Throw an exception if no callback' );
// Test invalid repository
testRepo.open( '/etc/hosts', function( err ) {
test.equals( -7, err, 'Invalid repository error code' );
// Test valid repository
testRepo.open( path.resolve( '../.git' ), function( err ) {
test.equals( 0, err, 'Valid repository error code' );
// testRepo.free();
test.done();
});
});
};
// TODO: Figure out how write unit tests for free
// Repo::Free
exports.free = function( test ) {
var testRepo = new git.Repo();
test.expect( 2 );
// Test for function
helper.testFunction( test.equals, testRepo.free, 'Repo::Free' );
test.done();
};
// Repo::Init
exports.init = function( test ) {
var testRepo = new git.Repo();
test.expect( 7 );
// Test for function
helper.testFunction( test.equals, testRepo.init, 'Repo::Init' );
// Test path argument existence
helper.testException( test.ok, function() {
testRepo.init();
}, 'Throw an exception if no path' );
// Test is_bare argument existence
helper.testException( test.ok, function() {
testRepo.init( "some/path" );
}, 'Throw an exception if no is_bare' );
// Test callback argument existence
helper.testException( test.ok, function() {
testRepo.init( "some/path", true );
}, 'Throw an exception if no callback' );
// Cleanup, remove test repo directory - if it exists
rimraf( './test.git', function() {
// Create bare repo and test for creation
testRepo.init( './test.git', true, function( err, path, is_bare ) {
test.equals( 0, err, 'Successfully created bare repository' );
// Verify repo exists
testRepo.open( './test.git', function(err, path) {
test.equals( 0, err, 'Valid repository created' );
testRepo.free();
// Cleanup, remove test repo directory
rimraf( './test.git', function() {
test.done();
});
});
});
});
};