Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions packages/dd-trace/test/plugins/util/git.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ require('../../setup/tap')

const { execSync } = require('child_process')
const os = require('os')
const fs = require('fs')
const path = require('path')

const { GIT_REV_LIST_MAX_BUFFER } = require('../../../src/plugins/util/git')
Expand Down Expand Up @@ -33,6 +34,13 @@ const { getGitMetadata } = proxyquire('../../../src/plugins/util/git',
}
)

function getFakeDirectory () {
if (os.platform() === 'win32') {
return `C:${path.sep}tmp`
}
return '/tmp'
}

describe('git', () => {
afterEach(() => {
sanitizedExecStub.reset()
Expand Down Expand Up @@ -169,11 +177,13 @@ describe('getCommitsToUpload', () => {
})

describe('generatePackFilesForCommits', () => {
let tmpdirStub
let tmpdirStub, statSyncStub
const fakeDirectory = getFakeDirectory()
beforeEach(() => {
sinon.stub(Math, 'random').returns('0.1234')
tmpdirStub = sinon.stub(os, 'tmpdir').returns('/tmp')
tmpdirStub = sinon.stub(os, 'tmpdir').returns(fakeDirectory)
sinon.stub(process, 'cwd').returns('cwd')
statSyncStub = sinon.stub(fs, 'statSync').returns({ isDirectory: () => true })
})
afterEach(() => {
sinon.restore()
Expand All @@ -189,7 +199,7 @@ describe('generatePackFilesForCommits', () => {
}
)

const temporaryPath = path.join('/tmp', '1234')
const temporaryPath = path.join(fakeDirectory, '1234')
const packFilesToUpload = generatePackFilesForCommits(['commitSHA'])
expect(packFilesToUpload).to.eql([`${temporaryPath}-commitSHA.pack`])
})
Expand All @@ -213,6 +223,7 @@ describe('generatePackFilesForCommits', () => {

it('does not work if tmpdir does not return a folder', () => {
tmpdirStub.restore()
statSyncStub.restore()
sinon.stub(os, 'tmpdir').returns('; echo hey')
const execFileSyncSpy = sinon.stub().onCall(0).throws().onCall(1).returns(['commitSHA'])

Expand Down