Skip to content

Commit 879fdc5

Browse files
committed
Fix tests
1 parent bd2d56a commit 879fdc5

File tree

1 file changed

+56
-16
lines changed

1 file changed

+56
-16
lines changed

packages/dd-trace/test/ci-visibility/exporters/git/git_metadata.spec.js

Lines changed: 56 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ describe('git_metadata', () => {
2828
let isShallowRepositoryStub
2929
let unshallowRepositoryStub
3030

31+
let isUnshallowEnabled
32+
3133
before(() => {
3234
process.env.DD_API_KEY = 'api-key'
3335
fs.writeFileSync(temporaryPackFile, '')
@@ -47,6 +49,8 @@ describe('git_metadata', () => {
4749
isShallowRepositoryStub = sinon.stub().returns(false)
4850
unshallowRepositoryStub = sinon.stub()
4951

52+
isUnshallowEnabled = true
53+
5054
generatePackFilesForCommitsStub = sinon.stub().returns([temporaryPackFile])
5155

5256
gitMetadata = proxyquire('../../../../src/ci-visibility/exporters/git/git_metadata', {
@@ -76,7 +80,8 @@ describe('git_metadata', () => {
7680
expect(err).to.be.null
7781
expect(scope.isDone()).to.be.true
7882
done()
79-
})
83+
},
84+
isUnshallowEnabled)
8085
})
8186

8287
it('should unshallow if the repo is shallow and not every commit is in the backend', (done) => {
@@ -94,7 +99,28 @@ describe('git_metadata', () => {
9499
expect(err).to.be.null
95100
expect(scope.isDone()).to.be.true
96101
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)
98124
})
99125

100126
it('should request to /api/v2/git/repository/search_commits and /api/v2/git/repository/packfile', (done) => {
@@ -108,7 +134,8 @@ describe('git_metadata', () => {
108134
expect(err).to.be.null
109135
expect(scope.isDone()).to.be.true
110136
done()
111-
})
137+
},
138+
isUnshallowEnabled)
112139
})
113140

114141
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', () => {
126153
expect(scope.isDone()).to.be.false
127154
expect(scope.pendingMocks()).to.contain('POST https://api.test.com:443/api/v2/git/repository/packfile')
128155
done()
129-
})
156+
},
157+
isUnshallowEnabled)
130158
})
131159

132160
it('should fail and not continue if first query results in anything other than 200', (done) => {
@@ -143,7 +171,8 @@ describe('git_metadata', () => {
143171
expect(scope.isDone()).to.be.false
144172
expect(scope.pendingMocks()).to.contain('POST https://api.test.com:443/api/v2/git/repository/packfile')
145173
done()
146-
})
174+
},
175+
isUnshallowEnabled)
147176
})
148177

149178
it('should fail and not continue if the response are not correct commits', (done) => {
@@ -159,7 +188,8 @@ describe('git_metadata', () => {
159188
expect(scope.isDone()).to.be.false
160189
expect(scope.pendingMocks()).to.contain('POST https://api.test.com:443/api/v2/git/repository/packfile')
161190
done()
162-
})
191+
},
192+
isUnshallowEnabled)
163193
})
164194

165195
it('should fail and not continue if the response are badly formatted commits', (done) => {
@@ -175,7 +205,8 @@ describe('git_metadata', () => {
175205
expect(scope.isDone()).to.be.false
176206
expect(scope.pendingMocks()).to.contain('POST https://api.test.com:443/api/v2/git/repository/packfile')
177207
done()
178-
})
208+
},
209+
isUnshallowEnabled)
179210
})
180211

181212
it('should fail if the packfile request returns anything other than 204', (done) => {
@@ -189,7 +220,8 @@ describe('git_metadata', () => {
189220
expect(err.message).to.contain('Could not upload packfiles: status code 502')
190221
expect(scope.isDone()).to.be.true
191222
done()
192-
})
223+
},
224+
isUnshallowEnabled)
193225
})
194226

195227
it('should fail if the getCommitsRevList fails because the repository is too big', (done) => {
@@ -203,7 +235,8 @@ describe('git_metadata', () => {
203235
expect(err.message).to.contain('git rev-list failed')
204236
expect(scope.isDone()).to.be.true
205237
done()
206-
})
238+
},
239+
isUnshallowEnabled)
207240
})
208241

209242
it('should fire a request per packfile', (done) => {
@@ -230,7 +263,8 @@ describe('git_metadata', () => {
230263
expect(err).to.be.null
231264
expect(scope.isDone()).to.be.true
232265
done()
233-
})
266+
},
267+
isUnshallowEnabled)
234268
})
235269

236270
describe('validateGitRepositoryUrl', () => {
@@ -305,7 +339,8 @@ describe('git_metadata', () => {
305339
expect(err.message).to.contain('Could not read "not-there"')
306340
expect(scope.isDone()).to.be.false
307341
done()
308-
})
342+
},
343+
isUnshallowEnabled)
309344
})
310345

311346
it('should not crash if generatePackFiles returns an empty array', (done) => {
@@ -321,7 +356,8 @@ describe('git_metadata', () => {
321356
expect(err.message).to.contain('Failed to generate packfiles')
322357
expect(scope.isDone()).to.be.false
323358
done()
324-
})
359+
},
360+
isUnshallowEnabled)
325361
})
326362

327363
it('should not crash if git is missing', (done) => {
@@ -340,7 +376,8 @@ describe('git_metadata', () => {
340376
expect(scope.isDone()).to.be.false
341377
process.env.PATH = oldPath
342378
done()
343-
})
379+
},
380+
isUnshallowEnabled)
344381
})
345382

346383
it('should retry if backend temporarily fails', (done) => {
@@ -358,7 +395,8 @@ describe('git_metadata', () => {
358395
expect(err).to.be.null
359396
expect(scope.isDone()).to.be.true
360397
done()
361-
})
398+
},
399+
isUnshallowEnabled)
362400
})
363401

364402
it('should append evp proxy prefix if configured', (done) => {
@@ -378,7 +416,8 @@ describe('git_metadata', () => {
378416
(err) => {
379417
expect(err).to.be.null
380418
expect(scope.isDone()).to.be.true
381-
})
419+
},
420+
isUnshallowEnabled)
382421
})
383422

384423
it('should use the input repository url and not call getRepositoryUrl', (done) => {
@@ -408,6 +447,7 @@ describe('git_metadata', () => {
408447
expect(repositoryUrl).to.equal('https://[email protected]')
409448
done()
410449
})
411-
})
450+
},
451+
isUnshallowEnabled)
412452
})
413453
})

0 commit comments

Comments
 (0)