@@ -28,6 +28,8 @@ describe('git_metadata', () => {
28
28
let isShallowRepositoryStub
29
29
let unshallowRepositoryStub
30
30
31
+ let isUnshallowEnabled
32
+
31
33
before ( ( ) => {
32
34
process . env . DD_API_KEY = 'api-key'
33
35
fs . writeFileSync ( temporaryPackFile , '' )
@@ -47,6 +49,8 @@ describe('git_metadata', () => {
47
49
isShallowRepositoryStub = sinon . stub ( ) . returns ( false )
48
50
unshallowRepositoryStub = sinon . stub ( )
49
51
52
+ isUnshallowEnabled = true
53
+
50
54
generatePackFilesForCommitsStub = sinon . stub ( ) . returns ( [ temporaryPackFile ] )
51
55
52
56
gitMetadata = proxyquire ( '../../../../src/ci-visibility/exporters/git/git_metadata' , {
@@ -76,7 +80,8 @@ describe('git_metadata', () => {
76
80
expect ( err ) . to . be . null
77
81
expect ( scope . isDone ( ) ) . to . be . true
78
82
done ( )
79
- } )
83
+ } ,
84
+ isUnshallowEnabled )
80
85
} )
81
86
82
87
it ( 'should unshallow if the repo is shallow and not every commit is in the backend' , ( done ) => {
@@ -94,7 +99,28 @@ describe('git_metadata', () => {
94
99
expect ( err ) . to . be . null
95
100
expect ( scope . isDone ( ) ) . to . be . true
96
101
done ( )
97
- } )
102
+ } ,
103
+ isUnshallowEnabled )
104
+ } )
105
+
106
+ it ( 'should not unshallow if the parameter to enable unshallow is false' , ( done ) => {
107
+ isUnshallowEnabled = false
108
+ const scope = nock ( 'https://api.test.com' )
109
+ . post ( '/api/v2/git/repository/search_commits' )
110
+ . reply ( 200 , JSON . stringify ( { data : [ ] } ) )
111
+ . post ( '/api/v2/git/repository/search_commits' ) // calls a second time after unshallowing
112
+ . reply ( 200 , JSON . stringify ( { data : [ ] } ) )
113
+ . post ( '/api/v2/git/repository/packfile' )
114
+ . reply ( 204 )
115
+
116
+ isShallowRepositoryStub . returns ( true )
117
+ gitMetadata . sendGitMetadata ( new URL ( 'https://api.test.com' ) , { isEvpProxy : false } , '' , ( err ) => {
118
+ expect ( unshallowRepositoryStub ) . not . to . have . been . called
119
+ expect ( err ) . to . be . null
120
+ expect ( scope . isDone ( ) ) . to . be . true
121
+ done ( )
122
+ } ,
123
+ isUnshallowEnabled )
98
124
} )
99
125
100
126
it ( 'should request to /api/v2/git/repository/search_commits and /api/v2/git/repository/packfile' , ( done ) => {
@@ -108,7 +134,8 @@ describe('git_metadata', () => {
108
134
expect ( err ) . to . be . null
109
135
expect ( scope . isDone ( ) ) . to . be . true
110
136
done ( )
111
- } )
137
+ } ,
138
+ isUnshallowEnabled )
112
139
} )
113
140
114
141
it ( 'should not request to /api/v2/git/repository/packfile if the backend has the commit info' , ( done ) => {
@@ -126,7 +153,8 @@ describe('git_metadata', () => {
126
153
expect ( scope . isDone ( ) ) . to . be . false
127
154
expect ( scope . pendingMocks ( ) ) . to . contain ( 'POST https://api.test.com:443/api/v2/git/repository/packfile' )
128
155
done ( )
129
- } )
156
+ } ,
157
+ isUnshallowEnabled )
130
158
} )
131
159
132
160
it ( 'should fail and not continue if first query results in anything other than 200' , ( done ) => {
@@ -143,7 +171,8 @@ describe('git_metadata', () => {
143
171
expect ( scope . isDone ( ) ) . to . be . false
144
172
expect ( scope . pendingMocks ( ) ) . to . contain ( 'POST https://api.test.com:443/api/v2/git/repository/packfile' )
145
173
done ( )
146
- } )
174
+ } ,
175
+ isUnshallowEnabled )
147
176
} )
148
177
149
178
it ( 'should fail and not continue if the response are not correct commits' , ( done ) => {
@@ -159,7 +188,8 @@ describe('git_metadata', () => {
159
188
expect ( scope . isDone ( ) ) . to . be . false
160
189
expect ( scope . pendingMocks ( ) ) . to . contain ( 'POST https://api.test.com:443/api/v2/git/repository/packfile' )
161
190
done ( )
162
- } )
191
+ } ,
192
+ isUnshallowEnabled )
163
193
} )
164
194
165
195
it ( 'should fail and not continue if the response are badly formatted commits' , ( done ) => {
@@ -175,7 +205,8 @@ describe('git_metadata', () => {
175
205
expect ( scope . isDone ( ) ) . to . be . false
176
206
expect ( scope . pendingMocks ( ) ) . to . contain ( 'POST https://api.test.com:443/api/v2/git/repository/packfile' )
177
207
done ( )
178
- } )
208
+ } ,
209
+ isUnshallowEnabled )
179
210
} )
180
211
181
212
it ( 'should fail if the packfile request returns anything other than 204' , ( done ) => {
@@ -189,7 +220,8 @@ describe('git_metadata', () => {
189
220
expect ( err . message ) . to . contain ( 'Could not upload packfiles: status code 502' )
190
221
expect ( scope . isDone ( ) ) . to . be . true
191
222
done ( )
192
- } )
223
+ } ,
224
+ isUnshallowEnabled )
193
225
} )
194
226
195
227
it ( 'should fail if the getCommitsRevList fails because the repository is too big' , ( done ) => {
@@ -203,7 +235,8 @@ describe('git_metadata', () => {
203
235
expect ( err . message ) . to . contain ( 'git rev-list failed' )
204
236
expect ( scope . isDone ( ) ) . to . be . true
205
237
done ( )
206
- } )
238
+ } ,
239
+ isUnshallowEnabled )
207
240
} )
208
241
209
242
it ( 'should fire a request per packfile' , ( done ) => {
@@ -230,7 +263,8 @@ describe('git_metadata', () => {
230
263
expect ( err ) . to . be . null
231
264
expect ( scope . isDone ( ) ) . to . be . true
232
265
done ( )
233
- } )
266
+ } ,
267
+ isUnshallowEnabled )
234
268
} )
235
269
236
270
describe ( 'validateGitRepositoryUrl' , ( ) => {
@@ -305,7 +339,8 @@ describe('git_metadata', () => {
305
339
expect ( err . message ) . to . contain ( 'Could not read "not-there"' )
306
340
expect ( scope . isDone ( ) ) . to . be . false
307
341
done ( )
308
- } )
342
+ } ,
343
+ isUnshallowEnabled )
309
344
} )
310
345
311
346
it ( 'should not crash if generatePackFiles returns an empty array' , ( done ) => {
@@ -321,7 +356,8 @@ describe('git_metadata', () => {
321
356
expect ( err . message ) . to . contain ( 'Failed to generate packfiles' )
322
357
expect ( scope . isDone ( ) ) . to . be . false
323
358
done ( )
324
- } )
359
+ } ,
360
+ isUnshallowEnabled )
325
361
} )
326
362
327
363
it ( 'should not crash if git is missing' , ( done ) => {
@@ -340,7 +376,8 @@ describe('git_metadata', () => {
340
376
expect ( scope . isDone ( ) ) . to . be . false
341
377
process . env . PATH = oldPath
342
378
done ( )
343
- } )
379
+ } ,
380
+ isUnshallowEnabled )
344
381
} )
345
382
346
383
it ( 'should retry if backend temporarily fails' , ( done ) => {
@@ -358,7 +395,8 @@ describe('git_metadata', () => {
358
395
expect ( err ) . to . be . null
359
396
expect ( scope . isDone ( ) ) . to . be . true
360
397
done ( )
361
- } )
398
+ } ,
399
+ isUnshallowEnabled )
362
400
} )
363
401
364
402
it ( 'should append evp proxy prefix if configured' , ( done ) => {
@@ -378,7 +416,8 @@ describe('git_metadata', () => {
378
416
( err ) => {
379
417
expect ( err ) . to . be . null
380
418
expect ( scope . isDone ( ) ) . to . be . true
381
- } )
419
+ } ,
420
+ isUnshallowEnabled )
382
421
} )
383
422
384
423
it ( 'should use the input repository url and not call getRepositoryUrl' , ( done ) => {
@@ -408,6 +447,7 @@ describe('git_metadata', () => {
408
447
expect ( repositoryUrl ) . to . equal ( 'https://[email protected] ' )
409
448
done ( )
410
449
} )
411
- } )
450
+ } ,
451
+ isUnshallowEnabled )
412
452
} )
413
453
} )
0 commit comments