-
Notifications
You must be signed in to change notification settings - Fork 253
Expand file tree
/
Copy pathgetGcp.js
More file actions
155 lines (148 loc) · 6.13 KB
/
getGcp.js
File metadata and controls
155 lines (148 loc) · 6.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
const assert = require('assert');
const withV4 = require('../../support/withV4');
const { PutObjectCommand,
GetObjectCommand,
CreateBucketCommand } = require('@aws-sdk/client-s3');
const BucketUtility = require('../../../lib/utility/bucket-util');
const {
gcpLocation,
gcpLocationMismatch,
genUniqID,
describeSkipIfNotMultiple,
} = require('../utils');
const bucket = `getgcp${genUniqID()}`;
const gcpObject = `gcpobject-${genUniqID()}`;
const emptyGcpObject = `emptyObject-${genUniqID()}`;
const bigObject = `bigObject-${genUniqID()}`;
const mismatchObject = `mismatch-${genUniqID()}`;
const body = Buffer.from('I am a body', 'utf8');
const bigBody = Buffer.alloc(10485760);
const bigBodyLen = bigBody.length;
const correctMD5 = 'be747eb4b75517bf6b3cf7c5fbb62f3a';
const emptyMD5 = 'd41d8cd98f00b204e9800998ecf8427e';
const bigMD5 = 'f1c9645dbc14efddc7d8a322685f26eb';
describe('Multiple backend get object', function testSuite() {
this.timeout(30000);
withV4(sigCfg => {
let bucketUtil;
let s3;
before(() => {
process.stdout.write('Creating bucket');
bucketUtil = new BucketUtility('default', sigCfg);
s3 = bucketUtil.s3;
return s3.send(new CreateBucketCommand({ Bucket: bucket }))
.catch(err => {
process.stdout.write(`Error creating bucket: ${err}\n`);
throw err;
});
});
after(() => {
process.stdout.write('Emptying bucket\n');
return bucketUtil.empty(bucket)
.then(() => {
process.stdout.write('Deleting bucket\n');
return bucketUtil.deleteOne(bucket);
})
.catch(err => {
process.stdout.write('Error emptying/deleting bucket: ' +
`${err}\n`);
throw err;
});
});
describeSkipIfNotMultiple('with objects in GCP', () => {
before(() => {
process.stdout.write('Putting object to GCP\n');
return s3.send(new PutObjectCommand({ Bucket: bucket, Key: gcpObject,
Body: body,
Metadata: { 'scal-location-constraint': gcpLocation },
})
.then(() => {
process.stdout.write('Putting 0-byte object to GCP\n');
return s3.send(new PutObjectCommand({ Bucket: bucket,
Key: emptyGcpObject,
Metadata: { 'scal-location-constraint': gcpLocation },
}));
})
.then(() => {
process.stdout.write('Putting large object to GCP\n');
return s3.send(new PutObjectCommand({ Bucket: bucket,
Key: bigObject, Body: bigBody,
Metadata: { 'scal-location-constraint': gcpLocation },
}));
})
.catch(err => {
process.stdout.write(`Error putting objects: ${err}\n`);
throw err;
}));
});
const getTests = [
{
msg: 'should get a 0-byte object from GCP',
input: { Bucket: bucket, Key: emptyGcpObject,
range: null, size: null },
output: { MD5: emptyMD5, contentRange: null },
},
{
msg: 'should get an object from GCP',
input: { Bucket: bucket, Key: gcpObject,
range: null, size: null },
output: { MD5: correctMD5, contentRange: null },
},
{
msg: 'should get a large object from GCP',
input: { Bucket: bucket, Key: bigObject,
range: null, size: null },
output: { MD5: bigMD5, contentRange: null },
},
{
msg: 'should get an object using range query from GCP',
input: { Bucket: bucket, Key: bigObject,
range: 'bytes=0-9', size: 10 },
output: { MD5: bigMD5,
contentRange: `bytes 0-9/${bigBodyLen}` },
},
];
getTests.forEach(test => {
const { Bucket, Key, range, size } = test.input;
const { MD5, contentRange } = test.output;
it(test.msg, done => {
s3.send(new GetObjectCommand({ Bucket, Key, Range: range })).then(res => {
if (range) {
assert.strictEqual(res.ContentLength, size);
assert.strictEqual(res.ContentRange, contentRange);
}
assert.strictEqual(res.ETag, `"${MD5}"`);
done();
})
.catch(err => {
assert.equal(err, null,
`Expected success but got error ${err}`);
done(err);
});
});
});
});
describeSkipIfNotMultiple('with bucketMatch set to false', () => {
beforeEach(done => {
s3.send(new PutObjectCommand({ Bucket: bucket, Key: mismatchObject, Body: body,
Metadata: { 'scal-location-constraint': gcpLocationMismatch } })).then(() => {
done();
})
.catch(err => {
assert.equal(err, null, `Err putting object: ${err}`);
done(err);
});
});
it('should get an object from GCP', done => {
s3.send(new GetObjectCommand({ Bucket: bucket, Key: mismatchObject })).then(res => {
assert.strictEqual(res.ETag, `"${correctMD5}"`);
done();
})
.catch(err => {
assert.equal(err, null, `Error getting object: ${err}`);
done(err);
});
});
});
});
});