-
Notifications
You must be signed in to change notification settings - Fork 255
Expand file tree
/
Copy pathput.js
More file actions
92 lines (84 loc) · 2.91 KB
/
put.js
File metadata and controls
92 lines (84 loc) · 2.91 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
const assert = require('assert');
const arsenal = require('arsenal');
const { GCP } = arsenal.storage.data.external.GCP;
const { genUniqID, gcpRetry } = require('../../../utils/gcpUtils');
const { getRealAwsConfig } =
require('../../../../aws-node-sdk/test/support/awsConfig');
const {
CreateBucketCommand,
DeleteBucketCommand,
PutObjectCommand,
} = require('@aws-sdk/client-s3');
const credentialOne = 'gcpbackend';
const bucketName = `cldsrvci-put-${genUniqID()}`;
describe('GCP: PUT Object', function testSuite() {
this.timeout(30000);
const config = getRealAwsConfig(credentialOne);
const gcpClient = new GCP(config);
before(async () => {
await gcpRetry(
gcpClient,
new CreateBucketCommand({ Bucket: bucketName }),
);
});
after(async () => {
const cmd = new DeleteBucketCommand({ Bucket: bucketName });
await gcpClient.send(cmd);
});
afterEach(function afterFn(done) {
if (!this.currentTest.key) {
done();
return;
}
gcpClient.deleteObject({
Bucket: bucketName,
Key: this.currentTest.key,
}, err => {
if (err) {
process.stdout.write(`err in deleting object ${err}\n`);
}
return done(err);
});
});
describe('with existing object in bucket', () => {
beforeEach(async function beforeFn() {
this.currentTest.key = `somekey-${genUniqID()}`;
const cmd = new PutObjectCommand({
Bucket: bucketName,
Key: this.currentTest.key,
});
const res = await gcpClient.send(cmd);
this.currentTest.uploadId = res.VersionId;
});
it('should overwrite object', function testFn(done) {
gcpClient.putObject({
Bucket: bucketName,
Key: this.test.key,
}, (err, res) => {
assert.notStrictEqual(res.VersionId, this.test.uploadId);
return done();
});
});
});
describe('without existing object in bucket', () => {
it('should successfully put object', function testFn(done) {
this.test.key = `somekey-${genUniqID()}`;
gcpClient.putObject({
Bucket: bucketName,
Key: this.test.key,
}, (err, putRes) => {
assert.equal(err, null,
`Expected success, got error ${err}`);
gcpClient.getObject({
Bucket: bucketName,
Key: this.test.key,
}, (getErr, getRes) => {
assert.equal(getErr, null,
`Expected success, got error ${getErr}`);
assert.strictEqual(getRes.VersionId, putRes.VersionId);
return done();
});
});
});
});
});