@@ -6,26 +6,28 @@ const { Action, Step } = require('../../src/proxy/actions');
6
6
chai . should ( ) ;
7
7
const expect = chai . expect ;
8
8
9
- describe ( 'writePack' , ( ) => {
9
+ describe . only ( 'writePack' , ( ) => {
10
10
let exec ;
11
+ let readdirSyncStub ;
11
12
let spawnSyncStub ;
12
13
let stepLogSpy ;
13
14
let stepSetContentSpy ;
14
15
let stepSetErrorSpy ;
15
16
16
17
beforeEach ( ( ) => {
17
- spawnSyncStub = sinon . stub ( ) . returns ( {
18
- stdout : 'git receive-pack output' ,
19
- stderr : '' ,
20
- status : 0
21
- } ) ;
18
+ spawnSyncStub = sinon . stub ( ) ;
19
+ readdirSyncStub = sinon . stub ( ) ;
20
+
21
+ readdirSyncStub . onFirstCall ( ) . returns ( [ 'old1.idx' ] ) ;
22
+ readdirSyncStub . onSecondCall ( ) . returns ( [ 'old1.idx' , 'new1.idx' ] ) ;
22
23
23
24
stepLogSpy = sinon . spy ( Step . prototype , 'log' ) ;
24
25
stepSetContentSpy = sinon . spy ( Step . prototype , 'setContent' ) ;
25
26
stepSetErrorSpy = sinon . spy ( Step . prototype , 'setError' ) ;
26
27
27
28
const writePack = proxyquire ( '../../src/proxy/processors/push-action/writePack' , {
28
- 'child_process' : { spawnSync : spawnSyncStub }
29
+ 'child_process' : { spawnSync : spawnSyncStub } ,
30
+ 'fs' : { readdirSync : readdirSyncStub } ,
29
31
} ) ;
30
32
31
33
exec = writePack . exec ;
@@ -50,28 +52,34 @@ describe('writePack', () => {
50
52
1234567890 ,
51
53
'test/repo'
52
54
) ;
53
- action . proxyGitPath = '/path/to/repo' ;
55
+ action . proxyGitPath = '/path/to' ;
56
+ action . repoName = 'repo' ;
54
57
} ) ;
55
58
56
59
it ( 'should execute git receive-pack with correct parameters' , async ( ) => {
60
+ const dummySpawnOutput = { stdout : 'git receive-pack output' , stderr : '' , status : 0 } ;
61
+ spawnSyncStub . returns ( dummySpawnOutput ) ;
62
+
57
63
const result = await exec ( req , action ) ;
58
64
59
- expect ( spawnSyncStub . calledOnce ) . to . be . true ;
65
+ expect ( spawnSyncStub . callCount ) . to . equal ( 2 ) ;
60
66
expect ( spawnSyncStub . firstCall . args [ 0 ] ) . to . equal ( 'git' ) ;
61
- expect ( spawnSyncStub . firstCall . args [ 1 ] ) . to . deep . equal ( [ 'receive-pack' , 'repo' ] ) ;
62
- expect ( spawnSyncStub . firstCall . args [ 2 ] ) . to . deep . equal ( {
63
- cwd : '/path/to/repo' ,
64
- input : 'pack data' ,
65
- encoding : 'utf-8'
67
+ expect ( spawnSyncStub . firstCall . args [ 1 ] ) . to . deep . equal ( [ 'config' , 'receive.unpackLimit' , '0' ] ) ;
68
+ expect ( spawnSyncStub . firstCall . args [ 2 ] ) . to . include ( { cwd : '/path/to/repo' } ) ;
69
+
70
+ expect ( spawnSyncStub . secondCall . args [ 0 ] ) . to . equal ( 'git' ) ;
71
+ expect ( spawnSyncStub . secondCall . args [ 1 ] ) . to . deep . equal ( [ 'receive-pack' , 'repo' ] ) ;
72
+ expect ( spawnSyncStub . secondCall . args [ 2 ] ) . to . include ( {
73
+ cwd : '/path/to' ,
74
+ input : 'pack data'
66
75
} ) ;
67
76
68
- expect ( stepLogSpy . calledWith ( 'executing git receive-pack repo' ) ) . to . be . true ;
69
- expect ( stepLogSpy . calledWith ( 'git receive-pack output' ) ) . to . be . true ;
70
-
71
- expect ( stepSetContentSpy . calledWith ( 'git receive-pack output' ) ) . to . be . true ;
77
+ expect ( stepLogSpy . calledWith ( 'new idx files: new1.idx' ) ) . to . be . true ;
78
+ expect ( stepSetContentSpy . calledWith ( dummySpawnOutput ) ) . to . be . true ;
72
79
73
80
expect ( result . steps ) . to . have . lengthOf ( 1 ) ;
74
81
expect ( result . steps [ 0 ] . error ) . to . be . false ;
82
+ expect ( result . newIdxFiles ) . to . deep . equal ( [ 'new1.idx' ] ) ;
75
83
} ) ;
76
84
77
85
it ( 'should handle errors from git receive-pack' , async ( ) => {
0 commit comments