Skip to content

Commit 77cc20c

Browse files
committed
feat: add aws test suites
1 parent 99c7a1c commit 77cc20c

File tree

26 files changed

+2689
-272
lines changed

26 files changed

+2689
-272
lines changed

.mdeprc.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ module.exports = {
88
post_exec: 'yarn coverage:report'
99
};
1010

11+
if (process.env.PROVIDER === 'aws') {
12+
module.exports.tests = './test/suites/providers/aws/*.js';
13+
}
14+
1115
switch (process.env.DB) {
1216
case 'sentinel':
1317
module.exports.services.push('redisSentinel');

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"test:e2e": "yarn test:e2e:cluster && yarn test:e2e:sentinel",
1111
"test:e2e:cluster": "DB=cluster mdep test run",
1212
"test:e2e:sentinel": "DB=sentinel mdep test run --docker_compose ./test/docker-compose.sentinel.yml",
13+
"test:e2e:aws-provider": "PROVIDER=aws DB=sentinel mdep test run --docker_compose ./test/docker-compose.sentinel.yml",
1314
"start": "mfleet",
1415
"lint": "eslint ./src ./test",
1516
"prepublishOnly": "yarn compile",

src/actions/upload.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const {
3838
* @return {Promise}
3939
*/
4040
async function initFileUpload({ params }) {
41+
console.log('init file upload');
4142
const {
4243
files,
4344
meta,

src/configs/core.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ exports.transport = [{
9393
* @returns {Provider}
9494
*/
9595
exports.selectTransport = function selectTransport() {
96+
// console.log('my provider 1', this.providers[0]);
9697
return this.providers[0];
9798
};
9899

src/providers/aws.js

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,15 @@ class AWSTransport extends AbstractFileTransfer {
125125
}
126126

127127
// @todo interface
128-
getDownloadUrlSigned(filename, downloadName) {
129-
this.log.warn(`${downloadName} is not implemented yet`);
130-
128+
getDownloadUrlSigned(filename) {
131129
const params = {
132-
Bucket: this._config.bucketName,
130+
Bucket: this.getBucketName(),
133131
Expires: DOWNLOAD_URL_EXPIRES_IN_SEC,
134132
Key: filename,
135133
};
136134

135+
console.log('params with Key', params);
136+
137137
return new Promise((resolve, reject) => {
138138
this._aws.getSignedUrl('putObject', params, (err, url) => {
139139
if (err) {
@@ -161,6 +161,7 @@ class AWSTransport extends AbstractFileTransfer {
161161
* @return {Promise}
162162
*/
163163
async initResumableUpload(opts) {
164+
console.log('init resumable upload');
164165
const params = {
165166
Bucket: this._config.bucket.name,
166167
Expires: DOWNLOAD_URL_EXPIRES_IN_SEC,
@@ -236,13 +237,18 @@ class AWSTransport extends AbstractFileTransfer {
236237
* @returns {Promise}
237238
*/
238239
createSignedURL(opts) {
240+
// console.log('createSignedURL opts 2', opts.resource.split('/')[opts.resource.length - 1]);
241+
// console.log('createSignedURL opts 2', opts);
242+
console.log('12345667890');
239243
const params = {
240244
Bucket: this._config.bucket.name,
241245
Expires: DOWNLOAD_URL_EXPIRES_IN_SEC,
242-
Key: opts.filename,
246+
Key: opts.resource,
243247
};
244248

245-
params.ContentType = opts.contentType;
249+
console.log('createSignedURL params', params);
250+
251+
// params.ContentType = opts.contentType;
246252

247253
return new Promise((resolve, reject) => {
248254
console.log('signed url params', params);
@@ -305,12 +311,10 @@ class AWSTransport extends AbstractFileTransfer {
305311
console.log(`exists method aws for: ${filename}`);
306312

307313
return new Promise((resolve) => {
308-
this._aws.headObject({ Key: filename, Bucket: this._config.bucket.name }, (err, data) => {
314+
this._aws.headObject({ Key: filename, Bucket: this._config.bucket.name }, (err) => {
309315
if (err) {
310-
console.log('exists err', err);
311316
return resolve(false);
312317
}
313-
console.log('exists data', data);
314318
return resolve(true);
315319
});
316320
});
@@ -322,7 +326,14 @@ class AWSTransport extends AbstractFileTransfer {
322326
* @return {Promise}
323327
*/
324328
remove(filename) {
325-
this.log.warn('the method is not implemented yet', { filename });
329+
return new Promise((resolve) => {
330+
this._aws.deleteObject({ Key: filename, Bucket: this._config.bucket.name }, (err) => {
331+
if (err) {
332+
return resolve(false);
333+
}
334+
return resolve(true);
335+
});
336+
});
326337
}
327338
}
328339

src/utils/fetch-data.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ async function selectMaster(redis) {
102102
* @param {String[]} [fieldsFilter.pick]
103103
*/
104104
module.exports = function fetchData(key, fieldFilter = {}) {
105+
console.log('fetch data for key', key);
105106
const { redis } = this;
106107
const timer = perf(`fetchData:${key}`);
107108

src/utils/process.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ module.exports = function processFile(key, data) {
3131
return Promise
3232
.using(acquireLock(this, `postprocess:${key}`), (lock) => {
3333
const { uploadId } = data;
34+
console.log('port srocess uploadId', uploadId);
3435
const { redis } = this;
3536

3637
return Promise

test/configs/generic/core.js

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,7 @@ exports.amqp = {
1919
},
2020
};
2121

22-
exports.transport = [
23-
// {
24-
// name: 'gce',
25-
// options: {
26-
// gce: {
27-
// projectId: env.GCLOUD_PROJECT_ID,
28-
// credentials: {
29-
// client_email: env.GCLOUD_PROJECT_EMAIL,
30-
// private_key: env.GCLOUD_PROJECT_PK,
31-
// },
32-
// },
33-
// bucket: {
34-
// name: env.TEST_BUCKET,
35-
// metadata: {
36-
// location: env.GCLOUD_BUCKET_LOCATION || 'EUROPE-WEST1',
37-
// dra: true,
38-
// },
39-
// },
40-
// // test for direct public URLs
41-
// },
42-
// // its not a public name!
43-
// cname: 'gce',
44-
// },
22+
const awsTransport = [
4523
{
4624
name: 'aws',
4725
options: {
@@ -58,7 +36,35 @@ exports.transport = [
5836
},
5937
// its not a public name!
6038
cname: 'aws',
61-
}];
39+
},
40+
];
41+
42+
// const gceTransport = [
43+
// {
44+
// name: 'gce',
45+
// options: {
46+
// gce: {
47+
// projectId: env.GCLOUD_PROJECT_ID,
48+
// credentials: {
49+
// client_email: env.GCLOUD_PROJECT_EMAIL,
50+
// private_key: env.GCLOUD_PROJECT_PK,
51+
// },
52+
// },
53+
// bucket: {
54+
// name: env.TEST_BUCKET,
55+
// metadata: {
56+
// location: env.GCLOUD_BUCKET_LOCATION || 'EUROPE-WEST1',
57+
// dra: true,
58+
// },
59+
// },
60+
// // test for direct public URLs
61+
// },
62+
// // its not a public name!
63+
// cname: 'gce',
64+
// },
65+
// ];
66+
67+
exports.transport = env.PROVIDER === 'aws' ? awsTransport : awsTransport;
6268

6369
exports.hooks = {
6470
// return input, assume there are models
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
version: '3'
2+
3+
services:
4+
tester:
5+
volumes:
6+
- ${PWD}:/src
7+
- ${PWD}/test/configs/generic:/configs/core:ro
8+
# - ${PWD}/test/configs/generic:/configs/aws:ro
9+
- ${PWD}/test/configs/redis-sentinel:/configs/redis:ro
10+
environment:
11+
NODE_ENV: "test"
12+
DEBUG: "${DEBUG}"
13+
TEST_BUCKET: "makeomatic-131232"
14+
DOTENV_FILE_PATH: "/src/test/.env"
15+
NCONF_FILE_PATH: '["/configs/core","/configs/redis"]'
16+
PROVIDER: 'aws'

test/helpers/utils.js

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -177,37 +177,40 @@ function modelSimpleUpload({
177177
// upload single file
178178
//
179179
function upload(location, file) {
180+
console.log('upload location', location);
180181
return request.put({
181182
url: location,
182183
body: file,
183-
headers: {
184-
'content-length': file.length,
185-
},
184+
// headers: {
185+
// 'content-length': file.length,
186+
// },
186187
simple: false,
187188
resolveWithFullResponse: true,
188189
});
189190
}
190191

191-
async function uploadSimple(meta, file, isPublic) {
192-
const { query: { Expires } } = url.parse(meta.location);
192+
async function uploadSimple(meta, file) {
193+
// const { query: { Expires } } = url.parse(meta.location);
193194

194-
const headers = {
195-
'Content-MD5': meta.md5Hash,
196-
'Cache-Control': `public,max-age=${Expires}`,
197-
'Content-Type': meta.contentType,
198-
};
195+
// const headers = {
196+
// 'Content-MD5': meta.md5Hash,
197+
// 'Cache-Control': `public,max-age=${Expires}`,
198+
// 'Content-Type': meta.contentType,
199+
// };
199200

200-
if (isPublic) {
201-
headers['x-goog-acl'] = 'public-read';
202-
}
201+
// if (isPublic) {
202+
// headers['x-goog-acl'] = 'public-read';
203+
// }
204+
205+
console.log('meta.location', meta);
203206

204207
return request.put({
205208
url: meta.location,
206209
body: file,
207210
// headers,
208211
// simple: false,
209212
resolveWithFullResponse: true,
210-
ACL: 'public-read',
213+
// ACL: 'public-read',
211214
});
212215
}
213216

@@ -217,6 +220,7 @@ async function uploadSimple(meta, file, isPublic) {
217220
// `rsp` is response to that message
218221
//
219222
function uploadFiles(msg, rsp) {
223+
console.log('upload files rsp', rsp);
220224
const { files } = msg;
221225
return Promise
222226
.map(rsp.files, (part, idx) => {
@@ -251,6 +255,7 @@ function initUpload(data) {
251255
return this.amqp
252256
.publishAndWait('files.upload', data.message, { timeout: 30000 })
253257
.tap((rsp) => {
258+
console.log('files upload res', rsp);
254259
this.response = rsp;
255260
})
256261
.tap((rsp) => uploadFiles(data, rsp));

0 commit comments

Comments
 (0)