-
-
Notifications
You must be signed in to change notification settings - Fork 184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
System binary #119
Merged
Merged
System binary #119
Changes from 11 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
1695bb5
test on CI
jtbairdsr 9e29683
fix unit test
jtbairdsr b9df877
fix prettier
jtbairdsr 9f773af
check that system binary exists
jtbairdsr edc536a
fix unit tests
jtbairdsr 2624826
refactor getPath method to consume several smaller methods
jtbairdsr 5d52125
update tests to excersize each smaller method individually
jtbairdsr c0f2bf0
fix flow typing issues
jtbairdsr 7c95849
check system binary version against requested version
jtbairdsr ffde320
update the README.md to include new option
jtbairdsr f672677
Merge branch 'master' into system-binary
nodkz f7e93fe
check that systemBinary exists before checking versions
jtbairdsr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,89 @@ | ||
/* @flow */ | ||
|
||
import tmp from 'tmp'; | ||
import fs from 'fs'; | ||
import os from 'os'; | ||
import MongoBinary from '../MongoBinary'; | ||
|
||
const MongoBinaryDownload: any = require('../MongoBinaryDownload'); | ||
|
||
tmp.setGracefulCleanup(); | ||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 600000; | ||
|
||
const mockGetMongodPath = jest.fn().mockResolvedValue('/temp/path'); | ||
|
||
jest.mock('../MongoBinaryDownload', () => { | ||
return jest.fn().mockImplementation(() => { | ||
return { getMongodPath: mockGetMongodPath }; | ||
}); | ||
}); | ||
|
||
describe('MongoBinary', () => { | ||
it('should download binary and keep it in cache', async () => { | ||
const tmpDir = tmp.dirSync({ prefix: 'mongo-mem-bin-', unsafeCleanup: true }); | ||
|
||
// download | ||
const version = 'latest'; | ||
const binPath = await MongoBinary.getPath({ | ||
downloadDir: tmpDir.name, | ||
version, | ||
let tmpDir; | ||
|
||
beforeEach(() => { | ||
tmpDir = tmp.dirSync({ prefix: 'mongo-mem-bin-', unsafeCleanup: true }); | ||
}); | ||
|
||
// cleanup | ||
afterEach(() => { | ||
tmpDir.removeCallback(); | ||
MongoBinaryDownload.mockClear(); | ||
mockGetMongodPath.mockClear(); | ||
MongoBinary.cache = {}; | ||
}); | ||
|
||
describe('getPath', () => { | ||
it('should get system binary from the environment', async () => { | ||
const accessSpy = jest.spyOn(fs, 'access'); | ||
process.env.MONGOMS_SYSTEM_BINARY = '/usr/local/bin/mongod'; | ||
await MongoBinary.getPath(); | ||
|
||
expect(accessSpy).toHaveBeenCalledWith('/usr/local/bin/mongod'); | ||
|
||
accessSpy.mockClear(); | ||
}); | ||
// eg. /tmp/mongo-mem-bin-33990ScJTSRNSsFYf/mongodb-download/a811facba94753a2eba574f446561b7e/mongodb-macOS-x86_64-3.5.5-13-g00ee4f5/ | ||
expect(binPath).toMatch(/mongo-mem-bin-.*\/.*\/mongod$/); | ||
|
||
// reuse cache | ||
expect(MongoBinary.cache[version]).toBeDefined(); | ||
expect(MongoBinary.cache[version]).toEqual(binPath); | ||
const binPathAgain = await MongoBinary.getPath({ | ||
downloadDir: tmpDir.name, | ||
version, | ||
}); | ||
|
||
describe('getDownloadPath', () => { | ||
it('should download binary and keep it in cache', async () => { | ||
// download | ||
const version = 'latest'; | ||
const binPath = await MongoBinary.getPath({ | ||
downloadDir: tmpDir.name, | ||
version, | ||
}); | ||
|
||
// eg. /tmp/mongo-mem-bin-33990ScJTSRNSsFYf/mongodb-download/a811facba94753a2eba574f446561b7e/mongodb-macOS-x86_64-3.5.5-13-g00ee4f5/ | ||
expect(MongoBinaryDownload).toHaveBeenCalledWith({ | ||
downloadDir: tmpDir.name, | ||
platform: os.platform(), | ||
arch: os.arch(), | ||
version, | ||
}); | ||
|
||
expect(mockGetMongodPath).toHaveBeenCalledTimes(1); | ||
|
||
expect(MongoBinary.cache[version]).toBeDefined(); | ||
expect(MongoBinary.cache[version]).toEqual(binPath); | ||
}); | ||
expect(binPathAgain).toEqual(binPath); | ||
}); | ||
|
||
// cleanup | ||
tmpDir.removeCallback(); | ||
describe('getCachePath', () => { | ||
it('should get the cache', async () => { | ||
MongoBinary.cache['3.4.2'] = '/bin/mongod'; | ||
await expect(MongoBinary.getCachePath('3.4.2')).resolves.toEqual('/bin/mongod'); | ||
}); | ||
}); | ||
|
||
it('should use cache', async () => { | ||
MongoBinary.cache['3.4.2'] = '/bin/mongod'; | ||
await expect(MongoBinary.getPath({ version: '3.4.2' })).resolves.toEqual('/bin/mongod'); | ||
describe('getSystemPath', () => { | ||
it('should use system binary if option is passed.', async () => { | ||
const accessSpy = jest.spyOn(fs, 'access'); | ||
await MongoBinary.getSystemPath('/usr/bin/mongod'); | ||
|
||
expect(accessSpy).toHaveBeenCalledWith('/usr/bin/mongod'); | ||
|
||
accessSpy.mockClear(); | ||
}); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be
And need to add check that
binaryPath
is not empty ;)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh yeah, good catch totally missed that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've just merged with the master (there was a conflict).
Pull changes before commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There were updated packages in master.
Maybe it helps to resolve #120
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👌 I made that fix and pushed.