Skip to content

Commit

Permalink
add test case for S3 Metadata functions
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeloffner committed Oct 4, 2023
1 parent 78c83c3 commit a8c993b
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 1 deletion.
66 changes: 66 additions & 0 deletions tests/functions/S3MetaData.cfc
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<!---
*
* Copyright (c) 2015, Lucee Assosication Switzerland. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
---><cfscript>
component extends="org.lucee.cfml.test.LuceeTestCase" {

//public function beforeTests(){}

//public function afterTests(){}


private struct function getCredencials() {
return server.getTestService("s3");
}

public function setUp(){
var s3=getCredencials();
if(!isNull(s3.accessKeyId)) {
application action="update" s3={
accessKeyId: s3.ACCESS_KEY_ID,
awsSecretKey: s3.SECRET_KEY
};
variables.s3Supported=true;
}
else
variables.s3Supported=false;
}

public function testStoreMetadata() localMode=true {
if(!variables.s3Supported) return;
var bucketName="#server.getTestService("s3").bucket_prefix#metadata-#listFirst(replace(server.lucee.version,".","","all"),"-")#";
var objectName="object";
var dir="s3://#bucketName#/#objectName#/";
if(DirectoryExists(dir)) directoryDelete(dir,true);
try {
assertFalse(DirectoryExists(dir));
directoryCreate(dir);

var md=s3GetMetaData(bucketName,objectName);
var countBefore=structCount(md);
s3SetMetaData(bucketName,objectName,{"susi":"Susanne"});
var md=s3GetMetaData(bucketName,objectName);
assertEquals(countBefore+1,structCount(md));
assertEquals("Susanne",md.susi);
}
finally {
if(DirectoryExists(dir))
directoryDelete(dir,true);
}
}
}
</cfscript>
2 changes: 1 addition & 1 deletion tests/functions/StoreMetaData.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ component extends="org.lucee.cfml.test.LuceeTestCase" {
public function testStoreMetadata() localMode=true {
if(!variables.s3Supported) return;

var dir="s3://" & server.getTestService("s3").bucket_prefix & "metadata-#lcase(hash(CreateGUID()))#/object/";
var dir="s3://" & server.getTestService("s3").bucket_prefix & "metadata-#lcase(listFirst(replace(server.lucee.version,".","","all"),"-"))#/object/";
if(DirectoryExists(dir)) directoryDelete(dir,true);
try {
assertFalse(DirectoryExists(dir));
Expand Down

0 comments on commit a8c993b

Please sign in to comment.