Skip to content

Commit 60937f4

Browse files
committed
step2: use send with gcp client on object tests instead of old helpers
1 parent 5302645 commit 60937f4

12 files changed

Lines changed: 486 additions & 497 deletions

File tree

tests/functional/raw-node/test/GCP/object/completeMpu.js

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,24 @@ const arsenal = require('arsenal');
44
const { ListObjectsCommand } = require('@aws-sdk/client-s3');
55
const { GCP, GcpUtils } = arsenal.storage.data.external.GCP;
66
const {
7-
gcpRequestRetry,
87
gcpClientRetry,
9-
setBucketClass,
108
gcpMpuSetup,
119
genUniqID,
1210
} = require('../../../utils/gcpUtils');
1311
const { getRealAwsConfig } =
1412
require('../../../../aws-node-sdk/test/support/awsConfig');
13+
const {
14+
CreateBucketCommand,
15+
DeleteBucketCommand,
16+
} = require('@aws-sdk/client-s3');
1517

1618
const credentialOne = 'gcpbackend';
1719
const bucketNames = {
1820
main: {
1921
Name: `somebucket-${genUniqID()}`,
20-
Type: 'MULTI_REGIONAL',
2122
},
2223
mpu: {
2324
Name: `mpubucket-${genUniqID()}`,
24-
Type: 'MULTI_REGIONAL',
2525
},
2626
};
2727
const numParts = 1024;
@@ -114,37 +114,34 @@ describe('GCP: Complete MPU', function testSuite() {
114114
return callback(err);
115115
});
116116
};
117-
async.eachSeries(bucketNames,
118-
(bucket, next) => gcpRequestRetry({
119-
method: 'PUT',
120-
bucket: bucket.Name,
121-
authCredentials: config.credentials,
122-
requestBody: setBucketClass(bucket.Type),
123-
}, 0, err => {
124-
if (err) {
125-
process.stdout.write(`err in creating bucket ${err}\n`);
126-
}
127-
return next(err);
128-
}),
117+
async.eachSeries(Object.values(bucketNames),
118+
(bucket, next) => {
119+
const cmd = new CreateBucketCommand({ Bucket: bucket.Name });
120+
gcpClient.send(cmd)
121+
.then(() => next())
122+
.catch(err => {
123+
process.stdout.write(`err in creating bucket ${err}\n`);
124+
return next(err);
125+
});
126+
},
129127
done);
130128
});
131129

132130
after(done => {
133-
async.eachSeries(bucketNames,
131+
async.eachSeries(Object.values(bucketNames),
134132
(bucket, next) => emptyBucket(gcpClient, bucket.Name, err => {
135133
assert.equal(err, null,
136134
`Expected success, but got error ${err}`);
137-
gcpRequestRetry({
138-
method: 'DELETE',
139-
bucket: bucket.Name,
140-
authCredentials: config.credentials,
141-
}, 0, err => {
142-
if (err) {
143-
process.stdout.write(
144-
`err in deleting bucket ${err}\n`);
145-
}
146-
return next(err);
147-
});
135+
const cmd = new DeleteBucketCommand({ Bucket: bucket.Name });
136+
gcpClient.send(cmd)
137+
.then(() => next())
138+
.catch(error => {
139+
if (error) {
140+
process.stdout.write(
141+
`err in deleting bucket ${error}\n`);
142+
}
143+
return next(error);
144+
});
148145
}),
149146
done);
150147
});

tests/functional/raw-node/test/GCP/object/copy.js

Lines changed: 48 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@ const assert = require('assert');
22
const async = require('async');
33
const arsenal = require('arsenal');
44
const { GCP } = arsenal.storage.data.external.GCP;
5-
const { makeGcpRequest } = require('../../../utils/makeRequest');
6-
const { gcpRequestRetry, genUniqID } = require('../../../utils/gcpUtils');
5+
const { genUniqID } = require('../../../utils/gcpUtils');
76
const { getRealAwsConfig } =
87
require('../../../../aws-node-sdk/test/support/awsConfig');
8+
const {
9+
CreateBucketCommand,
10+
DeleteBucketCommand,
11+
PutObjectCommand,
12+
} = require('@aws-sdk/client-s3');
913

1014
const credentialOne = 'gcpbackend';
1115
const bucketName = `somebucket-${genUniqID()}`;
@@ -16,29 +20,23 @@ describe('GCP: COPY Object', function testSuite() {
1620
const gcpClient = new GCP(config);
1721

1822
before(done => {
19-
gcpRequestRetry({
20-
method: 'PUT',
21-
bucket: bucketName,
22-
authCredentials: config.credentials,
23-
}, 0, err => {
24-
if (err) {
23+
const cmd = new CreateBucketCommand({ Bucket: bucketName });
24+
gcpClient.send(cmd)
25+
.then(() => done())
26+
.catch(err => {
2527
process.stdout.write(`err in creating bucket ${err}\n`);
26-
}
27-
return done(err);
28-
});
28+
return done(err);
29+
});
2930
});
3031

3132
after(done => {
32-
gcpRequestRetry({
33-
method: 'DELETE',
34-
bucket: bucketName,
35-
authCredentials: config.credentials,
36-
}, 0, err => {
37-
if (err) {
33+
const cmd = new DeleteBucketCommand({ Bucket: bucketName });
34+
gcpClient.send(cmd)
35+
.then(() => done())
36+
.catch(err => {
3837
process.stdout.write(`err in creating bucket ${err}\n`);
39-
}
40-
return done(err);
41-
});
38+
return done(err);
39+
});
4240
});
4341

4442
describe('without existing object in bucket', () => {
@@ -63,41 +61,38 @@ describe('GCP: COPY Object', function testSuite() {
6361
this.currentTest.key = `somekey-${genUniqID()}`;
6462
this.currentTest.copyKey = `copykey-${genUniqID()}`;
6563
this.currentTest.initValue = `${genUniqID()}`;
66-
makeGcpRequest({
67-
method: 'PUT',
68-
bucket: bucketName,
69-
objectKey: this.currentTest.copyKey,
70-
headers: {
71-
'x-goog-meta-value': this.currentTest.initValue,
64+
const cmd = new PutObjectCommand({
65+
Bucket: bucketName,
66+
Key: this.currentTest.copyKey,
67+
Metadata: {
68+
value: this.currentTest.initValue,
7269
},
73-
authCredentials: config.credentials,
74-
}, (err, res) => {
75-
if (err) {
76-
process.stdout.write(`err in creating object ${err}\n`);
77-
}
78-
this.currentTest.contentHash = res.headers['x-goog-hash'];
79-
return done(err);
8070
});
71+
gcpClient.send(cmd)
72+
.then(res => {
73+
this.currentTest.ETag = res.ETag;
74+
return done();
75+
})
76+
.catch(err => {
77+
process.stdout.write(`err in creating object ${err}\n`);
78+
return done(err);
79+
});
8180
});
8281

8382
afterEach(function afterFn(done) {
8483
async.parallel([
85-
next => makeGcpRequest({
86-
method: 'DELETE',
87-
bucket: bucketName,
88-
objectKey: this.currentTest.key,
89-
authCredentials: config.credentials,
84+
next => gcpClient.deleteObject({
85+
Bucket: bucketName,
86+
Key: this.currentTest.key,
9087
}, err => {
9188
if (err) {
9289
process.stdout.write(`err in deleting object ${err}\n`);
9390
}
9491
return next(err);
9592
}),
96-
next => makeGcpRequest({
97-
method: 'DELETE',
98-
bucket: bucketName,
99-
objectKey: this.currentTest.copyKey,
100-
authCredentials: config.credentials,
93+
next => gcpClient.deleteObject({
94+
Bucket: bucketName,
95+
Key: this.currentTest.copyKey,
10196
}, err => {
10297
if (err) {
10398
process.stdout
@@ -125,20 +120,17 @@ describe('GCP: COPY Object', function testSuite() {
125120
`Expected success, but got error ${err}`);
126121
return next();
127122
}),
128-
next => makeGcpRequest({
129-
method: 'HEAD',
130-
bucket: bucketName,
131-
objectKey: this.test.key,
132-
authCredentials: config.credentials,
123+
next => gcpClient.headObject({
124+
Bucket: bucketName,
125+
Key: this.test.key,
133126
}, (err, res) => {
134127
if (err) {
135128
process.stdout
136129
.write(`err in retrieving object ${err}\n`);
137130
return next(err);
138131
}
139-
assert.strictEqual(this.test.contentHash,
140-
res.headers['x-goog-hash']);
141-
assert.notStrictEqual(res.headers['x-goog-meta-value'],
132+
assert.strictEqual(res.ETag, this.test.ETag);
133+
assert.notStrictEqual(res.Metadata.value,
142134
this.test.initValue);
143135
return next();
144136
}),
@@ -158,20 +150,17 @@ describe('GCP: COPY Object', function testSuite() {
158150
`Expected success, but got error ${err}`);
159151
return next();
160152
}),
161-
next => makeGcpRequest({
162-
method: 'HEAD',
163-
bucket: bucketName,
164-
objectKey: this.test.key,
165-
authCredentials: config.credentials,
153+
next => gcpClient.headObject({
154+
Bucket: bucketName,
155+
Key: this.test.key,
166156
}, (err, res) => {
167157
if (err) {
168158
process.stdout
169159
.write(`err in retrieving object ${err}\n`);
170160
return next(err);
171161
}
172-
assert.strictEqual(this.test.contentHash,
173-
res.headers['x-goog-hash']);
174-
assert.strictEqual(res.headers['x-goog-meta-value'],
162+
assert.strictEqual(res.ETag, this.test.ETag);
163+
assert.strictEqual(res.Metadata.value,
175164
this.test.initValue);
176165
return next();
177166
}),

tests/functional/raw-node/test/GCP/object/delete.js

Lines changed: 47 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@ const assert = require('assert');
22
const async = require('async');
33
const arsenal = require('arsenal');
44
const { GCP } = arsenal.storage.data.external.GCP;
5-
const { makeGcpRequest } = require('../../../utils/makeRequest');
6-
const { gcpRequestRetry, genUniqID } = require('../../../utils/gcpUtils');
5+
const { genUniqID } = require('../../../utils/gcpUtils');
76
const { getRealAwsConfig } =
87
require('../../../../aws-node-sdk/test/support/awsConfig');
8+
const {
9+
CreateBucketCommand,
10+
DeleteBucketCommand,
11+
PutObjectCommand,
12+
GetObjectCommand,
13+
} = require('@aws-sdk/client-s3');
914

1015
const credentialOne = 'gcpbackend';
1116
const bucketName = `somebucket-${genUniqID()}`;
@@ -18,44 +23,37 @@ describe('GCP: DELETE Object', function testSuite() {
1823
const gcpClient = new GCP(config);
1924

2025
before(done => {
21-
gcpRequestRetry({
22-
method: 'PUT',
23-
bucket: bucketName,
24-
authCredentials: config.credentials,
25-
}, 0, err => {
26-
if (err) {
26+
const cmd = new CreateBucketCommand({ Bucket: bucketName });
27+
gcpClient.send(cmd)
28+
.then(() => done())
29+
.catch(err => {
2730
process.stdout.write(`err in creating bucket ${err}\n`);
28-
}
29-
return done(err);
30-
});
31+
return done(err);
32+
});
3133
});
3234

3335
after(done => {
34-
gcpRequestRetry({
35-
method: 'DELETE',
36-
bucket: bucketName,
37-
authCredentials: config.credentials,
38-
}, 0, err => {
39-
if (err) {
36+
const cmd = new DeleteBucketCommand({ Bucket: bucketName });
37+
gcpClient.send(cmd)
38+
.then(() => done())
39+
.catch(err => {
4040
process.stdout.write(`err in deleting bucket ${err}\n`);
41-
}
42-
return done(err);
43-
});
41+
return done(err);
42+
});
4443
});
4544

4645
describe('with existing object in bucket', () => {
4746
beforeEach(done => {
48-
makeGcpRequest({
49-
method: 'PUT',
50-
bucket: bucketName,
51-
objectKey,
52-
authCredentials: config.credentials,
53-
}, err => {
54-
if (err) {
55-
process.stdout.write(`err in creating object ${err}\n`);
56-
}
57-
return done(err);
47+
const cmd = new PutObjectCommand({
48+
Bucket: bucketName,
49+
Key: objectKey,
5850
});
51+
gcpClient.send(cmd)
52+
.then(() => done())
53+
.catch(err => {
54+
process.stdout.write(`err in creating object ${err}\n`);
55+
return done(err);
56+
});
5957
});
6058

6159
it('should successfully delete object', done => {
@@ -68,17 +66,25 @@ describe('GCP: DELETE Object', function testSuite() {
6866
`Expected success, got error ${err}`);
6967
return next();
7068
}),
71-
next => makeGcpRequest({
72-
method: 'GET',
73-
bucket: bucketName,
74-
objectKey,
75-
authCredentials: config.credentials,
76-
}, err => {
77-
assert(err);
78-
assert.strictEqual(err.statusCode, 404);
79-
assert.strictEqual(err.code, 'NoSuchKey');
80-
return next();
81-
}),
69+
next => {
70+
const cmd = new GetObjectCommand({
71+
Bucket: bucketName,
72+
Key: objectKey,
73+
});
74+
gcpClient.send(cmd)
75+
.then(() => {
76+
// Should not succeed
77+
assert.fail('Expected NoSuchKey error');
78+
})
79+
.catch(err => {
80+
assert(err);
81+
assert.strictEqual(
82+
err.$metadata && err.$metadata.httpStatusCode,
83+
404);
84+
assert.strictEqual(err.name, 'NoSuchKey');
85+
return next();
86+
});
87+
},
8288
], err => done(err));
8389
});
8490
});

0 commit comments

Comments
 (0)