Skip to content

Commit

Permalink
make sure buckets get deleted after the job
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeloffner committed Jul 12, 2024
1 parent 17262ed commit f4bb3b2
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
28 changes: 27 additions & 1 deletion tests/functions/S3Download.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Sorglos";
bucketName=bucketName, objectName=objectName,
accessKeyId=cred.ACCESS_KEY_ID, secretAccessKey=cred.SECRET_KEY, host=(isNull(cred.HOST)?nullvalue():cred.HOST));
}
arguments.spec.body();
arguments.spec.body({bucketName:bucketName,cred:cred});
}
finally {
Util::deleteBucketEL(cred,bucketName);
Expand All @@ -30,6 +30,8 @@ Sorglos";


it(title="download as binary", body = function( currentSpec ) {
var cred=currentSpec.cred;
var bucketName=currentSpec.bucketName;
createBucket(cred,bucketName);
var data=s3Download(bucket:bucketName,object:objectName,accessKeyId:cred.ACCESS_KEY_ID,secretAccessKey:cred.SECRET_KEY);
assertTrue(isBinary(data));
Expand All @@ -38,6 +40,8 @@ Sorglos";
});

it(title="download as string", body = function( currentSpec ) {
var cred=currentSpec.cred;
var bucketName=currentSpec.bucketName;
var data=s3Download(bucket:bucketName,object:objectName,charset:"UTF-8",accessKeyId:cred.ACCESS_KEY_ID,secretAccessKey:cred.SECRET_KEY);
assertTrue(isSimpleValue(data));
assertEquals(len(data),12);
Expand All @@ -46,6 +50,8 @@ Sorglos";

//////// FILE ///////////
it(title="download to file (fileOpen)", body = function( currentSpec ) {
var cred=currentSpec.cred;
var bucketName=currentSpec.bucketName;
var target=getDirectoryFromPath(getCurrentTemplatePath())&"temp.txt";
try {
s3Download(bucket:bucketName,object:objectName,target:fileOpen(target,"write"),accessKeyId:cred.ACCESS_KEY_ID,secretAccessKey:cred.SECRET_KEY);
Expand All @@ -61,6 +67,8 @@ Sorglos";


it(title="download to file (string path)", body = function( currentSpec ) {
var cred=currentSpec.cred;
var bucketName=currentSpec.bucketName;
var target=getDirectoryFromPath(getCurrentTemplatePath())&"temp.txt";
try {
s3Download(bucket:bucketName,object:objectName,target:target,accessKeyId:cred.ACCESS_KEY_ID,secretAccessKey:cred.SECRET_KEY);
Expand All @@ -76,6 +84,8 @@ Sorglos";

//////// UDF ///////////
it(title="download to UDF:line", body = function( currentSpec ) {
var cred=currentSpec.cred;
var bucketName=currentSpec.bucketName;
var data="";
s3Download(bucket:bucketName,object:objectName,target:function(line){
data&=line;
Expand All @@ -88,6 +98,8 @@ Sorglos";
});

it(title="download to UDF:line with charset", body = function( currentSpec ) {
var cred=currentSpec.cred;
var bucketName=currentSpec.bucketName;
var data="";
s3Download(bucket:bucketName,object:objectName,charset:"UTF-8",target:function(line){
data&=line;
Expand All @@ -100,6 +112,8 @@ Sorglos";
});

it(title="download to UDF:line with charset", body = function( currentSpec ) {
var cred=currentSpec.cred;
var bucketName=currentSpec.bucketName;
var data="";
s3Download(bucket:bucketName,object:objectName,charset:"UTF-8",target:function(string4){
data&=string4&":"&len(string4)&";";
Expand All @@ -113,6 +127,8 @@ Sor:4;glos:4;");
});

it(title="download to UDF:string with charset", body = function( currentSpec ) {
var cred=currentSpec.cred;
var bucketName=currentSpec.bucketName;
var data="";
s3Download(bucket:bucketName,object:objectName,charset:"UTF-8",target:function(string4){
data&=string4&":"&len(string4)&";";
Expand All @@ -126,6 +142,8 @@ Sor:4;glos:4;");
});

it(title="download to UDF:binary", body = function( currentSpec ) {
var cred=currentSpec.cred;
var bucketName=currentSpec.bucketName;
var data="";
s3Download(bucket:bucketName,object:objectName,charset:"UTF-8",target:function(binary5){
data&=len(binary5)&";";
Expand All @@ -141,6 +159,8 @@ Sor:4;glos:4;");

//////// COMPONENT ///////////
it(title="download to component:line", body = function( currentSpec ) {
var cred=currentSpec.cred;
var bucketName=currentSpec.bucketName;
var listener=new LineListener();
s3Download(bucket:bucketName,object:objectName,target:listener,accessKeyId:cred.ACCESS_KEY_ID,secretAccessKey:cred.SECRET_KEY);
var data=listener.getData();
Expand All @@ -150,6 +170,8 @@ Sor:4;glos:4;");
});

it(title="download to component:line with charset", body = function( currentSpec ) {
var cred=currentSpec.cred;
var bucketName=currentSpec.bucketName;
var listener=new LineListener();
s3Download(bucket:bucketName,object:objectName,charset:"UTF-8",target:listener,accessKeyId:cred.ACCESS_KEY_ID,secretAccessKey:cred.SECRET_KEY);
var data=listener.getData();
Expand All @@ -159,6 +181,8 @@ Sor:4;glos:4;");
});

it(title="download to component:string with charset", body = function( currentSpec ) {
var cred=currentSpec.cred;
var bucketName=currentSpec.bucketName;
var listener=new StringListener();
s3Download(bucket:bucketName,object:objectName,charset:"UTF-8",target:listener,accessKeyId:cred.ACCESS_KEY_ID,secretAccessKey:cred.SECRET_KEY);
var data=listener.getData();
Expand All @@ -167,6 +191,8 @@ Sor:4;glos:4;");
});

it(title="download to component:binary", body = function( currentSpec ) {
var cred=currentSpec.cred;
var bucketName=currentSpec.bucketName;
var listener=new BinaryListener();
s3Download(bucket:bucketName,object:objectName,target:listener,accessKeyId:cred.ACCESS_KEY_ID,secretAccessKey:cred.SECRET_KEY);
var data=listener.getData();
Expand Down
12 changes: 6 additions & 6 deletions tests/general/BigBucket.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ component extends="org.lucee.cfml.test.LuceeTestCase" labels="s3" {
var bucketName = Util::createBucketName("big");
var cred = Util::getAWSCredentials();
try {



// does the bucket exists?
// does the bucket exists?
if(!S3Exists(
bucketName:bucketName,
accessKeyId:cred.ACCESS_KEY_ID, secretAccessKey:cred.SECRET_KEY, host:(isNull(cred.HOST)?nullvalue():cred.HOST))) {
Expand All @@ -37,8 +34,7 @@ component extends="org.lucee.cfml.test.LuceeTestCase" labels="s3" {
accessKeyId:cred.ACCESS_KEY_ID, secretAccessKey:cred.SECRET_KEY, host:(isNull(cred.HOST)?nullvalue():cred.HOST));
}
}

arguments.spec.body();
arguments.spec.body({bucketName:bucketName,cred:cred});
}
finally {
Util::deleteBucketEL(cred,bucketName);
Expand All @@ -48,6 +44,8 @@ component extends="org.lucee.cfml.test.LuceeTestCase" labels="s3" {


it(title="checking with S3ListBucket", skip=Util::isAWSNotSupported(), body = function( currentSpec ) {
var cred=currentSpec.cred;
var bucketName=currentSpec.bucketName;
var cred=Util::getAWSCredentials()

if(records==0){
Expand All @@ -65,6 +63,8 @@ component extends="org.lucee.cfml.test.LuceeTestCase" labels="s3" {


it(title="checking with S3Exists", skip=Util::isAWSNotSupported(), body = function( currentSpec ) {
var cred=currentSpec.cred;
var bucketName=currentSpec.bucketName;
var cred=Util::getAWSCredentials()

var executionTime=getTickCount();
Expand Down

0 comments on commit f4bb3b2

Please sign in to comment.