mongodb-memory-server 2.1.0 → 2.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +64 -2
- package/lib/MongoMemoryReplSet.d.ts +57 -0
- package/lib/MongoMemoryReplSet.js +307 -0
- package/lib/MongoMemoryReplSet.js.flow +252 -0
- package/lib/MongoMemoryServer.d.ts +47 -0
- package/lib/MongoMemoryServer.js +76 -78
- package/lib/MongoMemoryServer.js.flow +22 -26
- package/lib/__tests__/multipleDB-test.js +68 -0
- package/lib/__tests__/replset-test.js +87 -0
- package/lib/__tests__/singleDB-test.js +43 -0
- package/lib/index.d.ts +6 -0
- package/lib/index.js +32 -14
- package/lib/index.js.flow +2 -1
- package/lib/types.d.ts +49 -0
- package/lib/types.js +1 -0
- package/lib/types.js.flow +60 -0
- package/lib/util/MongoBinary.d.ts +23 -0
- package/lib/util/MongoBinary.js +46 -42
- package/lib/util/MongoBinary.js.flow +13 -6
- package/lib/util/MongoBinaryDownload.d.ts +33 -0
- package/lib/util/MongoBinaryDownload.js +84 -73
- package/lib/util/MongoBinaryDownload.js.flow +5 -11
- package/lib/util/MongoBinaryDownloadUrl.d.ts +35 -0
- package/lib/util/MongoBinaryDownloadUrl.js +68 -31
- package/lib/util/MongoBinaryDownloadUrl.js.flow +12 -17
- package/lib/util/MongoInstance.d.ts +49 -0
- package/lib/util/MongoInstance.js +50 -32
- package/lib/util/MongoInstance.js.flow +12 -17
- package/lib/util/__tests__/MongoBinary-test.js +52 -0
- package/lib/util/__tests__/MongoBinaryDownload-test.js +42 -0
- package/lib/util/__tests__/MongoBinaryDownloadUrl-test.js +179 -0
- package/lib/util/__tests__/MongoInstance-test.js +133 -0
- package/lib/util/db_util.d.ts +20 -0
- package/lib/util/db_util.js +56 -0
- package/lib/util/db_util.js.flow +29 -0
- package/lib/util/mongo_killer.d.ts +0 -0
- package/lib/util/mongo_killer.js +5 -5
- package/package.json +36 -23
|
@@ -3,23 +3,18 @@
|
|
|
3
3
|
|
|
4
4
|
import getos from 'getos';
|
|
5
5
|
|
|
6
|
-
type OS = {
|
|
7
|
-
dist: string,
|
|
8
|
-
release?: string,
|
|
9
|
-
};
|
|
10
|
-
|
|
11
6
|
export type MongoBinaryDownloadUrlOpts = {
|
|
12
7
|
version: string,
|
|
13
8
|
platform: string,
|
|
14
9
|
arch: string,
|
|
15
|
-
os?: ?
|
|
10
|
+
os?: ?getos.Os,
|
|
16
11
|
};
|
|
17
12
|
|
|
18
13
|
export default class MongoBinaryDownloadUrl {
|
|
19
14
|
platform: string;
|
|
20
15
|
arch: string;
|
|
21
16
|
version: string;
|
|
22
|
-
os: ?
|
|
17
|
+
os: ?getos.Os;
|
|
23
18
|
|
|
24
19
|
constructor({ platform, arch, version, os }: MongoBinaryDownloadUrlOpts) {
|
|
25
20
|
this.platform = this.translatePlatform(platform);
|
|
@@ -90,7 +85,7 @@ export default class MongoBinaryDownloadUrl {
|
|
|
90
85
|
return name;
|
|
91
86
|
}
|
|
92
87
|
|
|
93
|
-
async getos(): Promise<
|
|
88
|
+
async getos(): Promise<getos.Os> {
|
|
94
89
|
return new Promise((resolve, reject) => {
|
|
95
90
|
getos((e: any, os: any) => {
|
|
96
91
|
if (e) reject(e);
|
|
@@ -99,7 +94,7 @@ export default class MongoBinaryDownloadUrl {
|
|
|
99
94
|
});
|
|
100
95
|
}
|
|
101
96
|
|
|
102
|
-
getLinuxOSVersionString(os:
|
|
97
|
+
getLinuxOSVersionString(os: getos.Os): string {
|
|
103
98
|
if (/ubuntu/i.test(os.dist)) {
|
|
104
99
|
return this.getUbuntuVersionString(os);
|
|
105
100
|
} else if (/elementary OS/i.test(os.dist)) {
|
|
@@ -119,7 +114,7 @@ export default class MongoBinaryDownloadUrl {
|
|
|
119
114
|
return this.getLegacyVersionString(os);
|
|
120
115
|
}
|
|
121
116
|
|
|
122
|
-
getDebianVersionString(os:
|
|
117
|
+
getDebianVersionString(os: getos.Os): string {
|
|
123
118
|
let name: string = 'debian';
|
|
124
119
|
const release: number = parseFloat(os.release);
|
|
125
120
|
if (release >= 9) {
|
|
@@ -132,7 +127,7 @@ export default class MongoBinaryDownloadUrl {
|
|
|
132
127
|
return name;
|
|
133
128
|
}
|
|
134
129
|
|
|
135
|
-
getFedoraVersionString(os:
|
|
130
|
+
getFedoraVersionString(os: getos.Os): string {
|
|
136
131
|
let name: string = 'rhel';
|
|
137
132
|
const fedoraVer: number = parseInt(os.release, 10);
|
|
138
133
|
if (fedoraVer > 18) {
|
|
@@ -145,7 +140,7 @@ export default class MongoBinaryDownloadUrl {
|
|
|
145
140
|
return name;
|
|
146
141
|
}
|
|
147
142
|
|
|
148
|
-
getRhelVersionString(os:
|
|
143
|
+
getRhelVersionString(os: getos.Os): string {
|
|
149
144
|
let name: string = 'rhel';
|
|
150
145
|
const { release } = os;
|
|
151
146
|
if (release) {
|
|
@@ -161,22 +156,22 @@ export default class MongoBinaryDownloadUrl {
|
|
|
161
156
|
}
|
|
162
157
|
|
|
163
158
|
// eslint-disable-next-line no-unused-vars
|
|
164
|
-
getElementaryOSVersionString(os:
|
|
159
|
+
getElementaryOSVersionString(os: getos.Os): string {
|
|
165
160
|
return 'ubuntu1404';
|
|
166
161
|
}
|
|
167
162
|
|
|
168
163
|
// eslint-disable-next-line no-unused-vars
|
|
169
|
-
getMintVersionString(os:
|
|
164
|
+
getMintVersionString(os: getos.Os): string {
|
|
170
165
|
// unfortunately getos doesn't return version for Mint
|
|
171
166
|
return 'ubuntu1404';
|
|
172
167
|
}
|
|
173
168
|
|
|
174
169
|
// eslint-disable-next-line no-unused-vars
|
|
175
|
-
getLegacyVersionString(os:
|
|
170
|
+
getLegacyVersionString(os: getos.Os): string {
|
|
176
171
|
return '';
|
|
177
172
|
}
|
|
178
173
|
|
|
179
|
-
getSuseVersionString(os:
|
|
174
|
+
getSuseVersionString(os: getos.Os): string {
|
|
180
175
|
const [release]: [string | null] = os.release.match(/(^11|^12)/) || [null];
|
|
181
176
|
|
|
182
177
|
if (release) {
|
|
@@ -185,7 +180,7 @@ export default class MongoBinaryDownloadUrl {
|
|
|
185
180
|
return '';
|
|
186
181
|
}
|
|
187
182
|
|
|
188
|
-
getUbuntuVersionString(os:
|
|
183
|
+
getUbuntuVersionString(os: getos.Os): string {
|
|
189
184
|
let name: string = 'ubuntu';
|
|
190
185
|
const ubuntuVer: string[] = os.release ? os.release.split('.') : [];
|
|
191
186
|
const majorVer: number = parseInt(ubuntuVer[0], 10);
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/// <reference types='node' />
|
|
2
|
+
|
|
3
|
+
import { ChildProcess, SpawnOptions } from 'child_process';
|
|
4
|
+
import { MongoBinaryOpts } from './MongoBinary';
|
|
5
|
+
import { DebugFn, DebugPropT, CallbackFn, StorageEngineT } from '../types';
|
|
6
|
+
|
|
7
|
+
export interface MongodOps {
|
|
8
|
+
// instance options
|
|
9
|
+
instance: {
|
|
10
|
+
port: number;
|
|
11
|
+
storageEngine?: StorageEngineT;
|
|
12
|
+
dbPath: string;
|
|
13
|
+
debug?: DebugPropT;
|
|
14
|
+
replSet?: string;
|
|
15
|
+
args?: string[];
|
|
16
|
+
auth?: boolean;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
// mongo binary options
|
|
20
|
+
binary?: MongoBinaryOpts;
|
|
21
|
+
|
|
22
|
+
// child process spawn options
|
|
23
|
+
spawn?: SpawnOptions;
|
|
24
|
+
|
|
25
|
+
debug?: DebugPropT;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export default class MongodbInstance {
|
|
29
|
+
static childProcessList: ChildProcess[];
|
|
30
|
+
|
|
31
|
+
opts: MongodOps;
|
|
32
|
+
debug: DebugFn;
|
|
33
|
+
childProcess: ChildProcess;
|
|
34
|
+
killerProcess: ChildProcess;
|
|
35
|
+
instanceReady: CallbackFn;
|
|
36
|
+
instanceFailed: CallbackFn;
|
|
37
|
+
|
|
38
|
+
constructor(opts: MongodOps);
|
|
39
|
+
|
|
40
|
+
static run(opts: MongodOps): Promise<MongodbInstance>;
|
|
41
|
+
prepareCommandArgs(): string[];
|
|
42
|
+
run(): Promise<MongodbInstance>;
|
|
43
|
+
kill(): Promise<MongodbInstance>;
|
|
44
|
+
getPid(): number | undefined;
|
|
45
|
+
errorHandler(err: string): void;
|
|
46
|
+
closeHandler(code: number): void;
|
|
47
|
+
stderrHandler(message: string | Buffer): void;
|
|
48
|
+
stdoutHandler(message: string | Buffer): void;
|
|
49
|
+
}
|
|
@@ -1,32 +1,43 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.default = void 0;
|
|
6
7
|
|
|
7
|
-
var _child_process = require(
|
|
8
|
+
var _child_process = require("child_process");
|
|
8
9
|
|
|
9
|
-
var _path = require(
|
|
10
|
+
var _path = _interopRequireDefault(require("path"));
|
|
10
11
|
|
|
11
|
-
var
|
|
12
|
+
var _MongoBinary = _interopRequireDefault(require("./MongoBinary"));
|
|
12
13
|
|
|
13
|
-
|
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
15
|
|
|
15
|
-
var
|
|
16
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
16
17
|
|
|
17
|
-
function
|
|
18
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
18
19
|
|
|
19
|
-
function
|
|
20
|
-
/* eslint-disable class-methods-use-this */
|
|
20
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
21
21
|
|
|
22
22
|
class MongodbInstance {
|
|
23
|
-
|
|
24
23
|
static run(opts) {
|
|
25
24
|
const instance = new this(opts);
|
|
26
25
|
return instance.run();
|
|
27
26
|
}
|
|
28
27
|
|
|
29
28
|
constructor(opts) {
|
|
29
|
+
_defineProperty(this, "opts", void 0);
|
|
30
|
+
|
|
31
|
+
_defineProperty(this, "debug", void 0);
|
|
32
|
+
|
|
33
|
+
_defineProperty(this, "childProcess", void 0);
|
|
34
|
+
|
|
35
|
+
_defineProperty(this, "killerProcess", void 0);
|
|
36
|
+
|
|
37
|
+
_defineProperty(this, "instanceReady", void 0);
|
|
38
|
+
|
|
39
|
+
_defineProperty(this, "instanceFailed", void 0);
|
|
40
|
+
|
|
30
41
|
this.opts = opts;
|
|
31
42
|
|
|
32
43
|
if (this.opts.debug) {
|
|
@@ -48,43 +59,45 @@ class MongodbInstance {
|
|
|
48
59
|
}
|
|
49
60
|
|
|
50
61
|
prepareCommandArgs() {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
port =
|
|
54
|
-
storageEngine =
|
|
55
|
-
dbPath =
|
|
56
|
-
|
|
57
|
-
|
|
62
|
+
const _this$opts$instance = this.opts.instance,
|
|
63
|
+
ip = _this$opts$instance.ip,
|
|
64
|
+
port = _this$opts$instance.port,
|
|
65
|
+
storageEngine = _this$opts$instance.storageEngine,
|
|
66
|
+
dbPath = _this$opts$instance.dbPath,
|
|
67
|
+
replSet = _this$opts$instance.replSet,
|
|
68
|
+
auth = _this$opts$instance.auth,
|
|
69
|
+
args = _this$opts$instance.args;
|
|
58
70
|
const result = [];
|
|
59
71
|
result.push('--bind_ip', ip || '127.0.0.1');
|
|
60
72
|
if (port) result.push('--port', port.toString());
|
|
61
73
|
if (storageEngine) result.push('--storageEngine', storageEngine);
|
|
62
74
|
if (dbPath) result.push('--dbpath', dbPath);
|
|
63
|
-
result.push('--noauth');
|
|
64
|
-
|
|
65
|
-
return result;
|
|
75
|
+
if (!auth) result.push('--noauth');
|
|
76
|
+
if (replSet) result.push('--replSet', replSet);
|
|
77
|
+
return result.concat(args || []);
|
|
66
78
|
}
|
|
67
79
|
|
|
68
80
|
run() {
|
|
69
81
|
var _this = this;
|
|
70
82
|
|
|
71
83
|
return _asyncToGenerator(function* () {
|
|
72
|
-
const launch = new Promise(
|
|
73
|
-
_this.instanceReady =
|
|
84
|
+
const launch = new Promise((resolve, reject) => {
|
|
85
|
+
_this.instanceReady = () => {
|
|
74
86
|
_this.debug('MongodbInstance: is ready!');
|
|
87
|
+
|
|
75
88
|
resolve(_this.childProcess);
|
|
76
89
|
};
|
|
77
|
-
|
|
90
|
+
|
|
91
|
+
_this.instanceFailed = err => {
|
|
78
92
|
_this.debug(`MongodbInstance: is failed: ${err.toString()}`);
|
|
93
|
+
|
|
79
94
|
if (_this.killerProcess) _this.killerProcess.kill();
|
|
80
95
|
reject(err);
|
|
81
96
|
};
|
|
82
97
|
});
|
|
83
|
-
|
|
84
|
-
const mongoBin = yield _MongoBinary2.default.getPath(_this.opts.binary);
|
|
98
|
+
const mongoBin = yield _MongoBinary.default.getPath(_this.opts.binary);
|
|
85
99
|
_this.childProcess = _this._launchMongod(mongoBin);
|
|
86
100
|
_this.killerProcess = _this._launchKiller(process.pid, _this.childProcess.pid);
|
|
87
|
-
|
|
88
101
|
yield launch;
|
|
89
102
|
return _this;
|
|
90
103
|
})();
|
|
@@ -95,11 +108,13 @@ class MongodbInstance {
|
|
|
95
108
|
|
|
96
109
|
return _asyncToGenerator(function* () {
|
|
97
110
|
if (_this2.childProcess && !_this2.childProcess.killed) {
|
|
98
|
-
yield new Promise(
|
|
111
|
+
yield new Promise(resolve => {
|
|
99
112
|
_this2.childProcess.once(`exit`, resolve);
|
|
113
|
+
|
|
100
114
|
_this2.childProcess.kill();
|
|
101
115
|
});
|
|
102
116
|
}
|
|
117
|
+
|
|
103
118
|
return _this2;
|
|
104
119
|
})();
|
|
105
120
|
}
|
|
@@ -116,14 +131,14 @@ class MongodbInstance {
|
|
|
116
131
|
childProcess.stdout.on('data', this.stdoutHandler.bind(this));
|
|
117
132
|
childProcess.on('close', this.closeHandler.bind(this));
|
|
118
133
|
childProcess.on('error', this.errorHandler.bind(this));
|
|
119
|
-
|
|
120
134
|
return childProcess;
|
|
121
135
|
}
|
|
122
136
|
|
|
123
137
|
_launchKiller(parentPid, childPid) {
|
|
124
138
|
// spawn process which kills itself and mongo process if current process is dead
|
|
125
|
-
const killer = (0, _child_process.spawn)(process.argv[0], [
|
|
126
|
-
|
|
139
|
+
const killer = (0, _child_process.spawn)(process.argv[0], [_path.default.resolve(__dirname, 'mongo_killer.js'), parentPid.toString(), childPid.toString()], {
|
|
140
|
+
stdio: 'pipe'
|
|
141
|
+
});
|
|
127
142
|
return killer;
|
|
128
143
|
}
|
|
129
144
|
|
|
@@ -141,8 +156,8 @@ class MongodbInstance {
|
|
|
141
156
|
|
|
142
157
|
stdoutHandler(message) {
|
|
143
158
|
this.debug(`${message.toString()}`);
|
|
144
|
-
|
|
145
159
|
const log = message.toString();
|
|
160
|
+
|
|
146
161
|
if (/waiting for connections on port/i.test(log)) {
|
|
147
162
|
this.instanceReady();
|
|
148
163
|
} else if (/addr already in use/i.test(log)) {
|
|
@@ -157,6 +172,9 @@ class MongodbInstance {
|
|
|
157
172
|
this.instanceFailed('Mongod shutting down');
|
|
158
173
|
}
|
|
159
174
|
}
|
|
175
|
+
|
|
160
176
|
}
|
|
177
|
+
|
|
161
178
|
exports.default = MongodbInstance;
|
|
162
|
-
|
|
179
|
+
|
|
180
|
+
_defineProperty(MongodbInstance, "childProcessList", []);
|
|
@@ -5,33 +5,27 @@ import { ChildProcess, spawn as spawnChild } from 'child_process';
|
|
|
5
5
|
import path from 'path';
|
|
6
6
|
import MongoBinary from './MongoBinary';
|
|
7
7
|
import type { MongoBinaryOpts } from './MongoBinary';
|
|
8
|
+
import type { DebugPropT, StorageEngineT, SpawnOptions } from '../types';
|
|
8
9
|
|
|
9
10
|
export type MongodOps = {
|
|
10
11
|
// instance options
|
|
11
12
|
instance: {
|
|
12
13
|
port: number,
|
|
13
14
|
ip?: string, // for binding to all IP addresses set it to `::,0.0.0.0`, by default '127.0.0.1'
|
|
14
|
-
storageEngine?:
|
|
15
|
+
storageEngine?: StorageEngineT,
|
|
15
16
|
dbPath: string,
|
|
16
|
-
debug?:
|
|
17
|
+
debug?: DebugPropT,
|
|
18
|
+
replSet?: string,
|
|
19
|
+
args?: string[],
|
|
20
|
+
auth?: boolean,
|
|
17
21
|
},
|
|
18
22
|
|
|
19
23
|
// mongo binary options
|
|
20
24
|
binary?: MongoBinaryOpts,
|
|
21
25
|
|
|
22
26
|
// child process spawn options
|
|
23
|
-
spawn?:
|
|
24
|
-
|
|
25
|
-
env?: Object,
|
|
26
|
-
argv0?: string,
|
|
27
|
-
stdio?: string | Array<any>,
|
|
28
|
-
detached?: boolean,
|
|
29
|
-
uid?: number,
|
|
30
|
-
gid?: number,
|
|
31
|
-
shell?: boolean | string,
|
|
32
|
-
},
|
|
33
|
-
|
|
34
|
-
debug?: boolean | Function,
|
|
27
|
+
spawn?: SpawnOptions,
|
|
28
|
+
debug?: DebugPropT,
|
|
35
29
|
};
|
|
36
30
|
|
|
37
31
|
export default class MongodbInstance {
|
|
@@ -75,16 +69,17 @@ export default class MongodbInstance {
|
|
|
75
69
|
}
|
|
76
70
|
|
|
77
71
|
prepareCommandArgs(): string[] {
|
|
78
|
-
const { ip, port, storageEngine, dbPath } = this.opts.instance;
|
|
72
|
+
const { ip, port, storageEngine, dbPath, replSet, auth, args } = this.opts.instance;
|
|
79
73
|
|
|
80
74
|
const result = [];
|
|
81
75
|
result.push('--bind_ip', ip || '127.0.0.1');
|
|
82
76
|
if (port) result.push('--port', port.toString());
|
|
83
77
|
if (storageEngine) result.push('--storageEngine', storageEngine);
|
|
84
78
|
if (dbPath) result.push('--dbpath', dbPath);
|
|
85
|
-
result.push('--noauth');
|
|
79
|
+
if (!auth) result.push('--noauth');
|
|
80
|
+
if (replSet) result.push('--replSet', replSet);
|
|
86
81
|
|
|
87
|
-
return result;
|
|
82
|
+
return result.concat(args || []);
|
|
88
83
|
}
|
|
89
84
|
|
|
90
85
|
async run(): Promise<MongodbInstance> {
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _tmp = _interopRequireDefault(require("tmp"));
|
|
4
|
+
|
|
5
|
+
var _MongoBinary = _interopRequireDefault(require("../MongoBinary"));
|
|
6
|
+
|
|
7
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
8
|
+
|
|
9
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
10
|
+
|
|
11
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
12
|
+
|
|
13
|
+
_tmp.default.setGracefulCleanup();
|
|
14
|
+
|
|
15
|
+
jasmine.DEFAULT_TIMEOUT_INTERVAL = 160000;
|
|
16
|
+
describe('MongoBinary', () => {
|
|
17
|
+
it('should download binary and keep it in cache',
|
|
18
|
+
/*#__PURE__*/
|
|
19
|
+
_asyncToGenerator(function* () {
|
|
20
|
+
const tmpDir = _tmp.default.dirSync({
|
|
21
|
+
prefix: 'mongo-mem-bin-',
|
|
22
|
+
unsafeCleanup: true
|
|
23
|
+
}); // download
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
const version = 'latest';
|
|
27
|
+
const binPath = yield _MongoBinary.default.getPath({
|
|
28
|
+
downloadDir: tmpDir.name,
|
|
29
|
+
version
|
|
30
|
+
}); // eg. /tmp/mongo-mem-bin-33990ScJTSRNSsFYf/mongodb-download/a811facba94753a2eba574f446561b7e/mongodb-macOS-x86_64-3.5.5-13-g00ee4f5/
|
|
31
|
+
|
|
32
|
+
expect(binPath).toMatch(/mongo-mem-bin-.*\/.*\/mongod$/); // reuse cache
|
|
33
|
+
|
|
34
|
+
expect(_MongoBinary.default.cache[version]).toBeDefined();
|
|
35
|
+
expect(_MongoBinary.default.cache[version]).toEqual(binPath);
|
|
36
|
+
const binPathAgain = yield _MongoBinary.default.getPath({
|
|
37
|
+
downloadDir: tmpDir.name,
|
|
38
|
+
version
|
|
39
|
+
});
|
|
40
|
+
expect(binPathAgain).toEqual(binPath); // cleanup
|
|
41
|
+
|
|
42
|
+
tmpDir.removeCallback();
|
|
43
|
+
}));
|
|
44
|
+
it('should use cache',
|
|
45
|
+
/*#__PURE__*/
|
|
46
|
+
_asyncToGenerator(function* () {
|
|
47
|
+
_MongoBinary.default.cache['3.4.2'] = '/bin/mongod';
|
|
48
|
+
yield expect(_MongoBinary.default.getPath({
|
|
49
|
+
version: '3.4.2'
|
|
50
|
+
})).resolves.toEqual('/bin/mongod');
|
|
51
|
+
}));
|
|
52
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _MongoBinaryDownload = _interopRequireDefault(require("../MongoBinaryDownload"));
|
|
4
|
+
|
|
5
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
6
|
+
|
|
7
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
8
|
+
|
|
9
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
10
|
+
|
|
11
|
+
describe('MongoBinaryDownload', () => {
|
|
12
|
+
it('should use direct download',
|
|
13
|
+
/*#__PURE__*/
|
|
14
|
+
_asyncToGenerator(function* () {
|
|
15
|
+
process.env['yarn_https-proxy'] = '';
|
|
16
|
+
process.env.yarn_proxy = '';
|
|
17
|
+
process.env['npm_config_https-proxy'] = '';
|
|
18
|
+
process.env.npm_config_proxy = '';
|
|
19
|
+
process.env.https_proxy = '';
|
|
20
|
+
process.env.http_proxy = '';
|
|
21
|
+
const du = new _MongoBinaryDownload.default({}); // $FlowFixMe
|
|
22
|
+
|
|
23
|
+
du.httpDownload = jest.fn();
|
|
24
|
+
yield du.download('https://fastdl.mongodb.org/osx/mongodb-osx-ssl-x86_64-3.6.3.tgz');
|
|
25
|
+
expect(du.httpDownload).toHaveBeenCalledTimes(1);
|
|
26
|
+
const callArg1 = du.httpDownload.mock.calls[0][0];
|
|
27
|
+
expect(callArg1.agent).toBeUndefined();
|
|
28
|
+
}));
|
|
29
|
+
it('should pick up proxy from env vars',
|
|
30
|
+
/*#__PURE__*/
|
|
31
|
+
_asyncToGenerator(function* () {
|
|
32
|
+
process.env['yarn_https-proxy'] = 'http://user:pass@proxy:8080';
|
|
33
|
+
const du = new _MongoBinaryDownload.default({}); // $FlowFixMe
|
|
34
|
+
|
|
35
|
+
du.httpDownload = jest.fn();
|
|
36
|
+
yield du.download('https://fastdl.mongodb.org/osx/mongodb-osx-ssl-x86_64-3.6.3.tgz');
|
|
37
|
+
expect(du.httpDownload).toHaveBeenCalledTimes(1);
|
|
38
|
+
const callArg1 = du.httpDownload.mock.calls[0][0];
|
|
39
|
+
expect(callArg1.agent).toBeDefined();
|
|
40
|
+
expect(callArg1.agent.options.href).toBe('http://user:pass@proxy:8080/');
|
|
41
|
+
}));
|
|
42
|
+
});
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _MongoBinaryDownloadUrl = _interopRequireDefault(require("../MongoBinaryDownloadUrl"));
|
|
4
|
+
|
|
5
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
6
|
+
|
|
7
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
8
|
+
|
|
9
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
10
|
+
|
|
11
|
+
describe('MongoBinaryDownloadUrl', () => {
|
|
12
|
+
describe('getDownloadUrl()', () => {
|
|
13
|
+
describe('for mac', () => {
|
|
14
|
+
it('above 3.0',
|
|
15
|
+
/*#__PURE__*/
|
|
16
|
+
_asyncToGenerator(function* () {
|
|
17
|
+
const du = new _MongoBinaryDownloadUrl.default({
|
|
18
|
+
platform: 'darwin',
|
|
19
|
+
arch: 'x64',
|
|
20
|
+
version: '3.6.3'
|
|
21
|
+
});
|
|
22
|
+
expect((yield du.getDownloadUrl())).toBe('https://fastdl.mongodb.org/osx/mongodb-osx-ssl-x86_64-3.6.3.tgz');
|
|
23
|
+
}));
|
|
24
|
+
it('below and include 3.0',
|
|
25
|
+
/*#__PURE__*/
|
|
26
|
+
_asyncToGenerator(function* () {
|
|
27
|
+
const du = new _MongoBinaryDownloadUrl.default({
|
|
28
|
+
platform: 'darwin',
|
|
29
|
+
arch: 'x64',
|
|
30
|
+
version: '3.0.0'
|
|
31
|
+
});
|
|
32
|
+
expect((yield du.getDownloadUrl())).toBe('https://fastdl.mongodb.org/osx/mongodb-osx-x86_64-3.0.0.tgz');
|
|
33
|
+
}));
|
|
34
|
+
});
|
|
35
|
+
it('for ubuntu',
|
|
36
|
+
/*#__PURE__*/
|
|
37
|
+
_asyncToGenerator(function* () {
|
|
38
|
+
const du = new _MongoBinaryDownloadUrl.default({
|
|
39
|
+
platform: 'linux',
|
|
40
|
+
arch: 'x64',
|
|
41
|
+
version: '3.6.3',
|
|
42
|
+
os: {
|
|
43
|
+
dist: 'Ubuntu Linux',
|
|
44
|
+
release: '14.04'
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
expect((yield du.getDownloadUrl())).toBe('https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu1404-3.6.3.tgz');
|
|
48
|
+
}));
|
|
49
|
+
it('for debian',
|
|
50
|
+
/*#__PURE__*/
|
|
51
|
+
_asyncToGenerator(function* () {
|
|
52
|
+
const du = new _MongoBinaryDownloadUrl.default({
|
|
53
|
+
platform: 'linux',
|
|
54
|
+
arch: 'x64',
|
|
55
|
+
version: '3.6.3',
|
|
56
|
+
os: {
|
|
57
|
+
dist: 'debian',
|
|
58
|
+
release: '8.1'
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
expect((yield du.getDownloadUrl())).toBe('https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-debian81-3.6.3.tgz');
|
|
62
|
+
}));
|
|
63
|
+
it('for win32',
|
|
64
|
+
/*#__PURE__*/
|
|
65
|
+
_asyncToGenerator(function* () {
|
|
66
|
+
const du = new _MongoBinaryDownloadUrl.default({
|
|
67
|
+
platform: 'win32',
|
|
68
|
+
arch: 'x64',
|
|
69
|
+
version: '3.6.3'
|
|
70
|
+
});
|
|
71
|
+
expect((yield du.getDownloadUrl())).toBe('https://fastdl.mongodb.org/win32/mongodb-win32-x86_64-2008plus-ssl-3.6.3.zip');
|
|
72
|
+
}));
|
|
73
|
+
it('fallback',
|
|
74
|
+
/*#__PURE__*/
|
|
75
|
+
_asyncToGenerator(function* () {
|
|
76
|
+
const du = new _MongoBinaryDownloadUrl.default({
|
|
77
|
+
platform: 'linux',
|
|
78
|
+
arch: 'x64',
|
|
79
|
+
version: '3.6.3',
|
|
80
|
+
os: {
|
|
81
|
+
dist: 'Gentoo Linux'
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
expect((yield du.getDownloadUrl())).toBe('https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.6.3.tgz');
|
|
85
|
+
}));
|
|
86
|
+
});
|
|
87
|
+
describe('getUbuntuVersionString()', () => {
|
|
88
|
+
const downloadUrl = new _MongoBinaryDownloadUrl.default({
|
|
89
|
+
platform: 'linux',
|
|
90
|
+
arch: 'x64',
|
|
91
|
+
version: '3.6.3'
|
|
92
|
+
});
|
|
93
|
+
it('should return a archive name for Ubuntu 14.10', () => {
|
|
94
|
+
expect(downloadUrl.getUbuntuVersionString({
|
|
95
|
+
dist: 'Ubuntu Linux',
|
|
96
|
+
release: '14.10'
|
|
97
|
+
})).toBe('ubuntu1410-clang');
|
|
98
|
+
});
|
|
99
|
+
it('should return a archive name for Ubuntu 14.04', () => {
|
|
100
|
+
expect(downloadUrl.getUbuntuVersionString({
|
|
101
|
+
dist: 'Ubuntu Linux',
|
|
102
|
+
release: '14.04'
|
|
103
|
+
})).toBe('ubuntu1404');
|
|
104
|
+
});
|
|
105
|
+
it('should return a archive name for Ubuntu 12.04', () => {
|
|
106
|
+
expect(downloadUrl.getUbuntuVersionString({
|
|
107
|
+
dist: 'Ubuntu Linux',
|
|
108
|
+
release: '12.04'
|
|
109
|
+
})).toBe('ubuntu1204');
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
describe('getDebianVersionString()', () => {
|
|
113
|
+
const downloadUrl = new _MongoBinaryDownloadUrl.default({
|
|
114
|
+
platform: 'linux',
|
|
115
|
+
arch: 'x64',
|
|
116
|
+
version: '3.6.3'
|
|
117
|
+
});
|
|
118
|
+
it('should return a archive name for debian 6.2', () => {
|
|
119
|
+
expect(downloadUrl.getDebianVersionString({
|
|
120
|
+
dist: 'debian',
|
|
121
|
+
release: '6.2'
|
|
122
|
+
})).toBe('debian');
|
|
123
|
+
});
|
|
124
|
+
it('should return a archive name for debian 7.0', () => {
|
|
125
|
+
expect(downloadUrl.getDebianVersionString({
|
|
126
|
+
dist: 'debian',
|
|
127
|
+
release: '7.0'
|
|
128
|
+
})).toBe('debian');
|
|
129
|
+
});
|
|
130
|
+
it('should return a archive name for debian 7.1', () => {
|
|
131
|
+
expect(downloadUrl.getDebianVersionString({
|
|
132
|
+
dist: 'debian',
|
|
133
|
+
release: '7.1'
|
|
134
|
+
})).toBe('debian71');
|
|
135
|
+
});
|
|
136
|
+
it('should return a archive name for debian 8.0', () => {
|
|
137
|
+
expect(downloadUrl.getDebianVersionString({
|
|
138
|
+
dist: 'debian',
|
|
139
|
+
release: '8.0'
|
|
140
|
+
})).toBe('debian71');
|
|
141
|
+
});
|
|
142
|
+
it('should return a archive name for debian 8.1', () => {
|
|
143
|
+
expect(downloadUrl.getDebianVersionString({
|
|
144
|
+
dist: 'debian',
|
|
145
|
+
release: '8.1'
|
|
146
|
+
})).toBe('debian81');
|
|
147
|
+
});
|
|
148
|
+
it('should return a archive name for debian 9.0', () => {
|
|
149
|
+
expect(downloadUrl.getDebianVersionString({
|
|
150
|
+
dist: 'debian',
|
|
151
|
+
release: '9.0'
|
|
152
|
+
})).toBe('debian92');
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
describe('getMintVersionString', () => {
|
|
156
|
+
const downloadUrl = new _MongoBinaryDownloadUrl.default({
|
|
157
|
+
platform: 'linux',
|
|
158
|
+
arch: 'x64',
|
|
159
|
+
version: '3.6.3'
|
|
160
|
+
});
|
|
161
|
+
it('should return an archive name for Linux Mint', () => {
|
|
162
|
+
expect(downloadUrl.getMintVersionString({
|
|
163
|
+
dist: 'Linux Mint'
|
|
164
|
+
})).toBe('ubuntu1404');
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
describe('getLegacyVersionString', () => {
|
|
168
|
+
const downloadUrl = new _MongoBinaryDownloadUrl.default({
|
|
169
|
+
platform: 'linux',
|
|
170
|
+
arch: 'x64',
|
|
171
|
+
version: '3.6.3'
|
|
172
|
+
});
|
|
173
|
+
it('should return an archive name for Gentoo Linux', () => {
|
|
174
|
+
expect(downloadUrl.getLegacyVersionString({
|
|
175
|
+
dist: 'Gentoo Linux'
|
|
176
|
+
})).toBe('');
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
});
|