Skip to content

Commit

Permalink
cleanup test
Browse files Browse the repository at this point in the history
  • Loading branch information
zspitzer committed Dec 28, 2024
1 parent 98dee24 commit f627f18
Showing 1 changed file with 67 additions and 89 deletions.
156 changes: 67 additions & 89 deletions test/tickets/LDEV5034.cfc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
component extends="org.lucee.cfml.test.LuceeTestCase" {
component extends="org.lucee.cfml.test.LuceeTestCase" {

function beforeAll(){
variables.baseDir = getTempDirectory() & "LDEV-5034/";
Expand All @@ -13,136 +13,114 @@ component extends="org.lucee.cfml.test.LuceeTestCase" {
};
};

function run( testResults, testBox ){
describe( "fileSetAccessMode", function(){
it( title="test extract preserves file masks", skip=isNotUnix(), body=function(){
function run( testResults, testBox ){
describe( "Round trip a set of files and dirs thru compress and extract tar", function(){
it( title="just files", skip=isNotUnix(), body=function(){
var srcDir = getTestDir( "files" );
var destDir = getTestDir( "files-extract" );
var tests = [];
var sourceFiles = [];
// create some files
arrayAppend( tests, _file( srcDir, "644.txt", "644" ) );
arrayAppend( tests, _file( srcDir, "743.txt", "743" ) );
arrayAppend( tests, _file( srcDir, "043.txt", "443" ) );
arrayAppend( tests, _file( srcDir, "400.txt", "400" ) );

testRoundTripCompressExtract( srcDir, destDir, tests, true );
arrayAppend( sourceFiles, _file( srcDir, "644.txt", "644" ) );
arrayAppend( sourceFiles, _file( srcDir, "743.txt", "743" ) );
arrayAppend( sourceFiles, _file( srcDir, "043.txt", "443" ) );
arrayAppend( sourceFiles, _file( srcDir, "400.txt", "400" ) );

testRoundTripCompressExtract( srcDir, destDir, sourceFiles );
});
it( title="test extract preserves file and directory masks - simple", skip=isNotUnix(), body=function(){

it( title="file and directory", skip=isNotUnix(), body=function(){
var srcDir = getTestDir( "mixed2" );
var destDir = getTestDir( "mixed2-extract" );
var tests = [];
// create dir
arrayAppend( tests, _dir(srcDir, "dir-755", "755" ) );
// create files
arrayAppend( tests, _file(srcDir, "644.txt", "644" ) );
// emptyDirs are skipped, add file
arrayAppend( tests, _file(srcDir & "dir-755/", "755-400.txt", "400" ) );

testRoundTripCompressExtract( srcDir, destDir, tests, true );
var sourceFiles = [];
arrayAppend( sourceFiles, _dir(srcDir, "dir-755", "755" ) );
arrayAppend( sourceFiles, _file(srcDir, "644.txt", "644" ) );
arrayAppend( sourceFiles, _file(srcDir & "dir-755/", "755-400.txt", "400" ) );

testRoundTripCompressExtract( srcDir, destDir, sourceFiles );
});

it( title="test extract preserves file and directory masks", skip=isNotUnix(), body=function(){
it( title="files and directories", skip=isNotUnix(), body=function(){
var srcDir = getTestDir( "mixed" );
var destDir = getTestDir( "mixed-extract" );
var tests = [];
var sourceFiles = [];
// create some dirs
arrayAppend( tests, _dir(srcDir, "dir-755", "755" ) );
arrayAppend( tests, _dir(srcDir, "dir-777", "777" ) );
arrayAppend( tests, _dir(srcDir, "dir-743", "743" ) );
arrayAppend( sourceFiles, _dir(srcDir, "dir-755", "755" ) );
arrayAppend( sourceFiles, _dir(srcDir, "dir-777", "777" ) );
arrayAppend( sourceFiles, _dir(srcDir, "dir-743", "743" ) );
// create some files
arrayAppend( tests, _file(srcDir, "644.txt", "644" ) );
arrayAppend( tests, _file(srcDir, "743.txt", "743" ) );
arrayAppend( tests, _file(srcDir, "043.txt", "443" ) );
arrayAppend( tests, _file(srcDir, "400.txt", "400" ) );
arrayAppend( sourceFiles, _file(srcDir, "644.txt", "644" ) );
arrayAppend( sourceFiles, _file(srcDir, "743.txt", "743" ) );
arrayAppend( sourceFiles, _file(srcDir, "043.txt", "443" ) );
arrayAppend( sourceFiles, _file(srcDir, "400.txt", "400" ) );
// emptyDirs are skipped, add some files to them
arrayAppend( tests, _file(srcDir & "dir-777/", "777-443.txt", "743" ) );
arrayAppend( tests, _file(srcDir & "dir-755/", "755-400.txt", "400" ) );
arrayAppend( tests, _file(srcDir & "dir-743/", "743-777.txt", "777" ) );
testRoundTripCompressExtract( srcDir, destDir, tests, true );
arrayAppend( sourceFiles, _file(srcDir & "dir-777/", "777-443.txt", "743" ) );
arrayAppend( sourceFiles, _file(srcDir & "dir-755/", "755-400.txt", "400" ) );
arrayAppend( sourceFiles, _file(srcDir & "dir-743/", "743-777.txt", "777" ) );

testRoundTripCompressExtract( srcDir, destDir, sourceFiles );
});
} );
}

private function testRoundTripCompressExtract( string srcDir, string destDir, array tests, boolean debug=false ){
if ( arguments.debug ){
systemOutput("-----------------tests", true);
loop array=tests item="local.test" {
structDelete( test, "dateLastModified");
systemOutput( test, true );
}
}

var files = directoryList( arguments.srcDir, true, "query");
var stSrc = QueryToStruct( files, "name" );
private function testRoundTripCompressExtract( string srcDir, string destDir,
array sourceFiles, boolean debug=false ){
if ( arguments.debug ){
systemOutput("-----------------files", true);
systemOutput(files.toString(), true);
systemOutput("-----------------stSrc", true);
loop collection=stSrc item="local.item"{
systemOutput( item, true );
systemOutput( "-----------------source files", true );
loop array=arguments.sourceFiles item="local.sourceFile" {
structDelete( sourceFile, "dateLastModified" );
systemOutput( sourceFile, true );
}
systemOutput("-----------------test", true);
}

loop array=tests item="local.test" {
if ( arguments.debug )
systemOutput( test, true );
var key = listLast( mid( test.name, len( arguments.srcDir ) + 1 ), "/" );
if ( arguments.debug )
systemOutput( key, true );
expect( stSrc ).toHaveKey( key );
if ( arguments.debug )
systemOutput( stSrc[ key ], true );
expect( test.mode ).toBe( stSrc[ key ].mode );
}

// compress the source files into a tar archive
var tarFile = getTempFile( getTempDirectory(), "LDEV-5034", ".tar.gz" );
// mode 0 here is important!!!!! default is 777 and ignore source permissions
compress( format="tgz", source=arguments.srcDir, target=tarFile, includeBaseFolder=false, mode=0 );

systemOutput(tarFile, true);
//systemOutput(tarFile, true);
var dest = arguments.destDir;
extract( "tgz", tarFile, dest );

var files = directoryList( arguments.srcDir, true, "query");
var extractedFiles = directoryList( dest, true, "query" );
var stExt = QueryToStruct( extractedFiles, "name" );
var stExtracted = QueryToStruct( extractedFiles, "name" );

if ( arguments.debug ){
systemOutput("-----------------sourceFiles", true);
systemOutput(files.toString(), true);
systemOutput("-----------------extractedFiles", true);
systemOutput(extractedFiles.toString(), true);

systemOutput("-----------------stExt", true);
loop collection=stExt item="local.item"{
systemOutput( "-----------------sourceFiles", true );
systemOutput( files.toString(), true );
systemOutput( "-----------------extractedFiles", true );
systemOutput( extractedFiles.toString(), true );
systemOutput( "-----------------stExtracted", true );
loop collection=stExtracted item="local.item"{
structDelete( item, "dateLastModified" );
systemOutput( item, true );
}
systemOutput("-----------------", true);
}
files = justFiles( files );
extractedFiles = justFiles( extractedFiles );

var files = justFiles( files );
var extractedFiles = justFiles( extractedFiles );
expect( files.recordcount ).toBe( extractedFiles.recordcount );

loop array=tests item="local.test" {
structDelete( test, "dateLastModified");
// check that after round tripping thru compress() and extract()
// the final files have the same permissions as the source files
loop array=arguments.sourceFiles item="local.sourceFile" {
if ( arguments.debug )
systemOutput( test, true );
var key = listLast (mid( test.name, len( arguments.srcDir ) + 1 ), "/" );
systemOutput( sourceFile, true );
var filename = listLast( mid( sourceFile.name, len( arguments.srcDir ) + 1 ), "/" );
if ( arguments.debug )
systemOutput( "key [#key#]", true );
expect( stExt ).toHaveKey( key );
systemOutput( "filename [#filename#]", true );
expect( stExtracted ).toHaveKey( filename );
if ( arguments.debug )
systemOutput( stExt[ key ], true );
expect( stExt[ key ].mode ).toBe( test.mode , test.name );
systemOutput( stExtracted[ filename ], true );
expect( stExtracted[ filename ].mode ).toBe( sourceFile.mode , sourceFile.name );
}
}

private function justFiles( qry ) {
var qry = duplicate( qry );
private function justFiles( srcQry ) {
var qry = duplicate( arguments.srcQry );
for(var row=qry.recordcount; row > 0; row--) {
if ( qry.type[ row ] != "File" )
if ( qry.type[ row ] != "File" )
queryDeleteRow( qry, row);
}
querySort( qry, "type" );
Expand All @@ -169,7 +147,7 @@ component extends="org.lucee.cfml.test.LuceeTestCase" {
mode: mode,
type: "file"
};
}
}

private function isNotUnix(){
return ( server.os.name contains "windows" );
Expand Down

0 comments on commit f627f18

Please sign in to comment.