Skip to content

Commit

Permalink
extend S3ListBucket test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeloffner committed Nov 22, 2023
1 parent c00f8f8 commit f7bc340
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
48 changes: 48 additions & 0 deletions tests/functions/S3ListBucket.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,25 @@ component extends="org.lucee.cfml.test.LuceeTestCase" labels="s3" {
it(title="check region with blackbaze",skip=Util::isBackBlazeNotSupported(), body = function( currentSpec ) {
testit(Util::getBackBlazeCredentials());
testUDF(Util::getBackBlazeCredentials());
testCFC(Util::getBackBlazeCredentials());
});

it(title="check with amazon",skip=Util::isAWSNotSupported(), body = function( currentSpec ) {
testit(Util::getAWSCredentials());
testUDF(Util::getAWSCredentials());
testCFC(Util::getAWSCredentials());
});

it(title="check with wasabi",skip=Util::isWasabiNotSupported(), body = function( currentSpec ) {
testit(Util::getWasabiCredentials());
testUDF(Util::getWasabiCredentials());
testCFC(Util::getWasabiCredentials());
});

it(title="check with google",skip=Util::isGoogleNotSupported(), body = function( currentSpec ) {
testit(Util::getGoogleCredentials());
testUDF(Util::getGoogleCredentials());
testCFC(Util::getGoogleCredentials());
});

});
Expand Down Expand Up @@ -55,6 +59,50 @@ component extends="org.lucee.cfml.test.LuceeTestCase" labels="s3" {
}
}

private function testCFC(cred) {
try {
// create variables
var bucketName=cred.PREFIX&"-list-bucket:"&listFirst(replace(server.lucee.version,".","","all"),"-");
var objectNames=["sub/test1.txt","sub/test2.txt","sub/test3.txt","sub/test4.txt","sub/test5.txt"];

// create empty bucket
Util::deleteIfExists(cred,bucketName);
S3CreateBucket(
bucketName:bucketName,
accessKeyId:cred.ACCESS_KEY_ID, secretAccessKey:cred.SECRET_KEY, host:(isNull(cred.HOST)?nullvalue():cred.HOST));

// create objects
loop array=objectNames item="local.objectName" {
// create source bucket
if(!S3Exists(
bucketName:bucketName, objectName:objectName,
accessKeyId:cred.ACCESS_KEY_ID, secretAccessKey:cred.SECRET_KEY, host:(isNull(cred.HOST)?nullvalue():cred.HOST))) {
S3Write(
value:"Susi Sorglos",
bucketName:bucketName, objectName:objectName,
accessKeyId:cred.ACCESS_KEY_ID, secretAccessKey:cred.SECRET_KEY, host:(isNull(cred.HOST)?nullvalue():cred.HOST));
}
}

var listener=new S3ListBucketListener();
S3ListBucket(
bucketName:bucketName,
listener:listener,
blockfactor:3,
accessKeyId:cred.ACCESS_KEY_ID,
secretAccessKey:cred.SECRET_KEY,
host:(isNull(cred.HOST)?nullvalue():cred.HOST)
);
assertEquals("->3;2;<-", listener.getData());
}
catch(e) {
if(!findNoCase("Transaction cap exceeded", e.message) ) throw e;
}
finally {
Util::deleteBucketEL(cred,bucketName);
}
}

private function testUDF(cred) {
try {
// create variables
Expand Down
18 changes: 18 additions & 0 deletions tests/functions/S3ListBucketListener.cfc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
component {
variables.res="";

function before(){
variables.res&="-->";
}
function after(){
variables.res&="<--";
}

function invoke(data){
variables.res&=data.recordcount&";";
}

function getData() {
return variables.res;
}
}

0 comments on commit f7bc340

Please sign in to comment.