Skip to content

Commit

Permalink
additional test cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
kherock committed Jun 7, 2020
1 parent a854689 commit 7e38a25
Showing 1 changed file with 19 additions and 38 deletions.
57 changes: 19 additions & 38 deletions test/controllers/object.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

const AWS = require('aws-sdk');
const { expect } = require('chai');
const express = require('express');
const FormData = require('form-data');
Expand All @@ -14,8 +13,6 @@ const request = require('request-promise-native').defaults({
});
const { URL, URLSearchParams } = require('url');

const S3rver = require('../..');

const { createServerAndClient, generateTestObjects } = require('../helpers');

describe('Operations on Objects', () => {
Expand Down Expand Up @@ -849,35 +846,19 @@ describe('Operations on Objects', () => {

it('stores an object in a bucket after all objects are deleted', async function() {
const bucket = 'foobars';

const server = new S3rver();
const { port } = await server.run();
const s3Client = new AWS.S3({
accessKeyId: 'S3RVER',
secretAccessKey: 'S3RVER',
endpoint: `http://localhost:${port}`,
sslEnabled: false,
s3ForcePathStyle: true,
});
try {
await s3Client.createBucket({ Bucket: bucket }).promise();
await s3Client
.putObject({ Bucket: bucket, Key: 'foo.txt', Body: 'Hello!' })
.promise();
await s3Client
.deleteObject({ Bucket: bucket, Key: 'foo.txt' })
.promise();
await s3Client
.putObject({ Bucket: bucket, Key: 'foo2.txt', Body: 'Hello2!' })
.promise();
} finally {
await server.close();
}
await s3Client.createBucket({ Bucket: bucket }).promise();
await s3Client
.putObject({ Bucket: bucket, Key: 'foo.txt', Body: 'Hello!' })
.promise();
await s3Client.deleteObject({ Bucket: bucket, Key: 'foo.txt' }).promise();
await s3Client
.putObject({ Bucket: bucket, Key: 'foo2.txt', Body: 'Hello2!' })
.promise();
});
});

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

Expand All @@ -895,7 +876,7 @@ describe('Operations on Objects', () => {
.copyObject({
Bucket: 'bucket-b',
Key: destKey,
CopySource: '/' + 'bucket-a' + '/' + srcKey,
CopySource: '/bucket-a/' + srcKey,
})
.promise();
expect(copyResult.ETag).to.equal(data.ETag);
Expand All @@ -909,7 +890,7 @@ describe('Operations on Objects', () => {
expect(object.ETag).to.equal(data.ETag);
});

it('copys an image object into another bucket including its metadata', async function() {
it('copies an image object into another bucket including its metadata', async function() {
const srcKey = 'image';
const destKey = 'image/jamie';

Expand All @@ -931,7 +912,7 @@ describe('Operations on Objects', () => {
Bucket: 'bucket-b',
Key: destKey,
// MetadataDirective is implied to be COPY
CopySource: '/' + 'bucket-a' + '/' + srcKey,
CopySource: '/bucket-a/' + srcKey,
})
.promise();
const object = await s3Client
Expand All @@ -942,7 +923,7 @@ describe('Operations on Objects', () => {
expect(object.ETag).to.equal(data.ETag);
});

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

Expand All @@ -960,14 +941,14 @@ describe('Operations on Objects', () => {
.copyObject({
Bucket: 'bucket-a',
Key: destKey,
CopySource: '/' + 'bucket-a' + '/' + encodeURI(srcKey),
CopySource: '/bucket-a/' + encodeURI(srcKey),
})
.promise();
expect(copyResult.ETag).to.equal(data.ETag);
expect(moment(copyResult.LastModified).isValid()).to.be.true;
});

it('copys an image object into another bucket and update its metadata', async function() {
it('copies an image object into another bucket and update its metadata', async function() {
const srcKey = 'image';
const destKey = 'image/jamie';

Expand All @@ -984,7 +965,7 @@ describe('Operations on Objects', () => {
.copyObject({
Bucket: 'bucket-b',
Key: destKey,
CopySource: '/' + 'bucket-a' + '/' + srcKey,
CopySource: '/bucket-a/' + srcKey,
MetadataDirective: 'REPLACE',
Metadata: {
someKey: 'value',
Expand Down Expand Up @@ -1016,7 +997,7 @@ describe('Operations on Objects', () => {
.copyObject({
Bucket: 'bucket-b',
Key: destKey,
CopySource: '/' + 'bucket-a' + '/' + srcKey,
CopySource: '/bucket-a/' + srcKey,
MetadataDirective: 'REPLACE',
Metadata: {
someKey: 'value',
Expand Down Expand Up @@ -1049,7 +1030,7 @@ describe('Operations on Objects', () => {
.copyObject({
Bucket: 'bucket-a',
Key: key,
CopySource: '/' + 'bucket-a' + '/' + key,
CopySource: '/bucket-a/' + key,
Metadata: {
someKey: 'value',
},
Expand All @@ -1069,7 +1050,7 @@ describe('Operations on Objects', () => {
.copyObject({
Bucket: 'bucket-b',
Key: 'image/jamie',
CopySource: '/' + 'bucket-a' + '/doesnotexist',
CopySource: '/bucket-a/doesnotexist',
})
.promise();
} catch (err) {
Expand Down

0 comments on commit 7e38a25

Please sign in to comment.