Skip to content

Commit 4b8a1db

Browse files
committed
additional test cleanup
1 parent 6f1cf68 commit 4b8a1db

File tree

1 file changed

+19
-38
lines changed

1 file changed

+19
-38
lines changed

test/controllers/object.spec.js

+19-38
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
'use strict';
22

3-
const AWS = require('aws-sdk');
43
const { expect } = require('chai');
54
const express = require('express');
65
const FormData = require('form-data');
@@ -14,8 +13,6 @@ const request = require('request-promise-native').defaults({
1413
});
1514
const { URL, URLSearchParams } = require('url');
1615

17-
const S3rver = require('../..');
18-
1916
const { createServerAndClient, generateTestObjects } = require('../helpers');
2017

2118
describe('Operations on Objects', () => {
@@ -849,35 +846,19 @@ describe('Operations on Objects', () => {
849846

850847
it('stores an object in a bucket after all objects are deleted', async function() {
851848
const bucket = 'foobars';
852-
853-
const server = new S3rver();
854-
const { port } = await server.run();
855-
const s3Client = new AWS.S3({
856-
accessKeyId: 'S3RVER',
857-
secretAccessKey: 'S3RVER',
858-
endpoint: `http://localhost:${port}`,
859-
sslEnabled: false,
860-
s3ForcePathStyle: true,
861-
});
862-
try {
863-
await s3Client.createBucket({ Bucket: bucket }).promise();
864-
await s3Client
865-
.putObject({ Bucket: bucket, Key: 'foo.txt', Body: 'Hello!' })
866-
.promise();
867-
await s3Client
868-
.deleteObject({ Bucket: bucket, Key: 'foo.txt' })
869-
.promise();
870-
await s3Client
871-
.putObject({ Bucket: bucket, Key: 'foo2.txt', Body: 'Hello2!' })
872-
.promise();
873-
} finally {
874-
await server.close();
875-
}
849+
await s3Client.createBucket({ Bucket: bucket }).promise();
850+
await s3Client
851+
.putObject({ Bucket: bucket, Key: 'foo.txt', Body: 'Hello!' })
852+
.promise();
853+
await s3Client.deleteObject({ Bucket: bucket, Key: 'foo.txt' }).promise();
854+
await s3Client
855+
.putObject({ Bucket: bucket, Key: 'foo2.txt', Body: 'Hello2!' })
856+
.promise();
876857
});
877858
});
878859

879860
describe('PUT Object - Copy', () => {
880-
it('copys an image object into another bucket', async function() {
861+
it('copies an image object into another bucket', async function() {
881862
const srcKey = 'image';
882863
const destKey = 'image/jamie';
883864

@@ -895,7 +876,7 @@ describe('Operations on Objects', () => {
895876
.copyObject({
896877
Bucket: 'bucket-b',
897878
Key: destKey,
898-
CopySource: '/' + 'bucket-a' + '/' + srcKey,
879+
CopySource: '/bucket-a/' + srcKey,
899880
})
900881
.promise();
901882
expect(copyResult.ETag).to.equal(data.ETag);
@@ -909,7 +890,7 @@ describe('Operations on Objects', () => {
909890
expect(object.ETag).to.equal(data.ETag);
910891
});
911892

912-
it('copys an image object into another bucket including its metadata', async function() {
893+
it('copies an image object into another bucket including its metadata', async function() {
913894
const srcKey = 'image';
914895
const destKey = 'image/jamie';
915896

@@ -931,7 +912,7 @@ describe('Operations on Objects', () => {
931912
Bucket: 'bucket-b',
932913
Key: destKey,
933914
// MetadataDirective is implied to be COPY
934-
CopySource: '/' + 'bucket-a' + '/' + srcKey,
915+
CopySource: '/bucket-a/' + srcKey,
935916
})
936917
.promise();
937918
const object = await s3Client
@@ -942,7 +923,7 @@ describe('Operations on Objects', () => {
942923
expect(object.ETag).to.equal(data.ETag);
943924
});
944925

945-
it('copys an object using spaces/unicode chars in keys', async function() {
926+
it('copies an object using spaces/unicode chars in keys', async function() {
946927
const srcKey = 'awesome 驚くばかり.jpg';
947928
const destKey = 'new 新しい.jpg';
948929

@@ -960,14 +941,14 @@ describe('Operations on Objects', () => {
960941
.copyObject({
961942
Bucket: 'bucket-a',
962943
Key: destKey,
963-
CopySource: '/' + 'bucket-a' + '/' + encodeURI(srcKey),
944+
CopySource: '/bucket-a/' + encodeURI(srcKey),
964945
})
965946
.promise();
966947
expect(copyResult.ETag).to.equal(data.ETag);
967948
expect(moment(copyResult.LastModified).isValid()).to.be.true;
968949
});
969950

970-
it('copys an image object into another bucket and update its metadata', async function() {
951+
it('copies an image object into another bucket and update its metadata', async function() {
971952
const srcKey = 'image';
972953
const destKey = 'image/jamie';
973954

@@ -984,7 +965,7 @@ describe('Operations on Objects', () => {
984965
.copyObject({
985966
Bucket: 'bucket-b',
986967
Key: destKey,
987-
CopySource: '/' + 'bucket-a' + '/' + srcKey,
968+
CopySource: '/bucket-a/' + srcKey,
988969
MetadataDirective: 'REPLACE',
989970
Metadata: {
990971
someKey: 'value',
@@ -1016,7 +997,7 @@ describe('Operations on Objects', () => {
1016997
.copyObject({
1017998
Bucket: 'bucket-b',
1018999
Key: destKey,
1019-
CopySource: '/' + 'bucket-a' + '/' + srcKey,
1000+
CopySource: '/bucket-a/' + srcKey,
10201001
MetadataDirective: 'REPLACE',
10211002
Metadata: {
10221003
someKey: 'value',
@@ -1049,7 +1030,7 @@ describe('Operations on Objects', () => {
10491030
.copyObject({
10501031
Bucket: 'bucket-a',
10511032
Key: key,
1052-
CopySource: '/' + 'bucket-a' + '/' + key,
1033+
CopySource: '/bucket-a/' + key,
10531034
Metadata: {
10541035
someKey: 'value',
10551036
},
@@ -1069,7 +1050,7 @@ describe('Operations on Objects', () => {
10691050
.copyObject({
10701051
Bucket: 'bucket-b',
10711052
Key: 'image/jamie',
1072-
CopySource: '/' + 'bucket-a' + '/doesnotexist',
1053+
CopySource: '/bucket-a/doesnotexist',
10731054
})
10741055
.promise();
10751056
} catch (err) {

0 commit comments

Comments
 (0)