1
1
'use strict' ;
2
2
3
- const AWS = require ( 'aws-sdk' ) ;
4
3
const { expect } = require ( 'chai' ) ;
5
4
const express = require ( 'express' ) ;
6
5
const FormData = require ( 'form-data' ) ;
@@ -14,8 +13,6 @@ const request = require('request-promise-native').defaults({
14
13
} ) ;
15
14
const { URL , URLSearchParams } = require ( 'url' ) ;
16
15
17
- const S3rver = require ( '../..' ) ;
18
-
19
16
const { createServerAndClient, generateTestObjects } = require ( '../helpers' ) ;
20
17
21
18
describe ( 'Operations on Objects' , ( ) => {
@@ -849,35 +846,19 @@ describe('Operations on Objects', () => {
849
846
850
847
it ( 'stores an object in a bucket after all objects are deleted' , async function ( ) {
851
848
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 ( ) ;
876
857
} ) ;
877
858
} ) ;
878
859
879
860
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 ( ) {
881
862
const srcKey = 'image' ;
882
863
const destKey = 'image/jamie' ;
883
864
@@ -895,7 +876,7 @@ describe('Operations on Objects', () => {
895
876
. copyObject ( {
896
877
Bucket : 'bucket-b' ,
897
878
Key : destKey ,
898
- CopySource : '/' + ' bucket-a' + ' /' + srcKey ,
879
+ CopySource : '/bucket-a/' + srcKey ,
899
880
} )
900
881
. promise ( ) ;
901
882
expect ( copyResult . ETag ) . to . equal ( data . ETag ) ;
@@ -909,7 +890,7 @@ describe('Operations on Objects', () => {
909
890
expect ( object . ETag ) . to . equal ( data . ETag ) ;
910
891
} ) ;
911
892
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 ( ) {
913
894
const srcKey = 'image' ;
914
895
const destKey = 'image/jamie' ;
915
896
@@ -931,7 +912,7 @@ describe('Operations on Objects', () => {
931
912
Bucket : 'bucket-b' ,
932
913
Key : destKey ,
933
914
// MetadataDirective is implied to be COPY
934
- CopySource : '/' + ' bucket-a' + ' /' + srcKey ,
915
+ CopySource : '/bucket-a/' + srcKey ,
935
916
} )
936
917
. promise ( ) ;
937
918
const object = await s3Client
@@ -942,7 +923,7 @@ describe('Operations on Objects', () => {
942
923
expect ( object . ETag ) . to . equal ( data . ETag ) ;
943
924
} ) ;
944
925
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 ( ) {
946
927
const srcKey = 'awesome 驚くばかり.jpg' ;
947
928
const destKey = 'new 新しい.jpg' ;
948
929
@@ -960,14 +941,14 @@ describe('Operations on Objects', () => {
960
941
. copyObject ( {
961
942
Bucket : 'bucket-a' ,
962
943
Key : destKey ,
963
- CopySource : '/' + ' bucket-a' + ' /' + encodeURI ( srcKey ) ,
944
+ CopySource : '/bucket-a/' + encodeURI ( srcKey ) ,
964
945
} )
965
946
. promise ( ) ;
966
947
expect ( copyResult . ETag ) . to . equal ( data . ETag ) ;
967
948
expect ( moment ( copyResult . LastModified ) . isValid ( ) ) . to . be . true ;
968
949
} ) ;
969
950
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 ( ) {
971
952
const srcKey = 'image' ;
972
953
const destKey = 'image/jamie' ;
973
954
@@ -984,7 +965,7 @@ describe('Operations on Objects', () => {
984
965
. copyObject ( {
985
966
Bucket : 'bucket-b' ,
986
967
Key : destKey ,
987
- CopySource : '/' + ' bucket-a' + ' /' + srcKey ,
968
+ CopySource : '/bucket-a/' + srcKey ,
988
969
MetadataDirective : 'REPLACE' ,
989
970
Metadata : {
990
971
someKey : 'value' ,
@@ -1016,7 +997,7 @@ describe('Operations on Objects', () => {
1016
997
. copyObject ( {
1017
998
Bucket : 'bucket-b' ,
1018
999
Key : destKey ,
1019
- CopySource : '/' + ' bucket-a' + ' /' + srcKey ,
1000
+ CopySource : '/bucket-a/' + srcKey ,
1020
1001
MetadataDirective : 'REPLACE' ,
1021
1002
Metadata : {
1022
1003
someKey : 'value' ,
@@ -1049,7 +1030,7 @@ describe('Operations on Objects', () => {
1049
1030
. copyObject ( {
1050
1031
Bucket : 'bucket-a' ,
1051
1032
Key : key ,
1052
- CopySource : '/' + ' bucket-a' + ' /' + key ,
1033
+ CopySource : '/bucket-a/' + key ,
1053
1034
Metadata : {
1054
1035
someKey : 'value' ,
1055
1036
} ,
@@ -1069,7 +1050,7 @@ describe('Operations on Objects', () => {
1069
1050
. copyObject ( {
1070
1051
Bucket : 'bucket-b' ,
1071
1052
Key : 'image/jamie' ,
1072
- CopySource : '/' + ' bucket-a' + ' /doesnotexist',
1053
+ CopySource : '/bucket-a/doesnotexist' ,
1073
1054
} )
1074
1055
. promise ( ) ;
1075
1056
} catch ( err ) {
0 commit comments