Skip to content

Commit

Permalink
Merge pull request #2404 from zspitzer/LDEV-5034-filesetacessmode
Browse files Browse the repository at this point in the history
LDEV-5034 test cases for FileSetAccessMode and extract( "tgz" )
  • Loading branch information
michaeloffner authored Aug 13, 2024
2 parents 651f36e + 48447c9 commit 60897bc
Show file tree
Hide file tree
Showing 2 changed files with 195 additions and 0 deletions.
85 changes: 85 additions & 0 deletions test/functions/FileSetAccessMode.cfc
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
component extends="org.lucee.cfml.test.LuceeTestCase" {

function beforeAll(){
variables.dir = getTempDirectory() & "fileSetAccessMode/";
if ( directoryExists( dir ) )
directoryDelete( dir, true );
directoryCreate( dir );
};

function afterAll(){
if ( directoryExists( dir ) ){
directoryDelete( dir, true );
};
};

function run( testResults, testBox ){
describe( "fileSetAccessMode", function(){
it( title="test access modes", skip=isNotUnix(), body=function(){
var tests = [];

arrayAppend( tests, _dir( dir, "755", "755" ) );
arrayAppend( tests, _dir( dir, "777", "777" ) );
arrayAppend( tests, _dir( dir, "644", "644" ) );

var files = directoryList( dir, true, "query");
var st = QueryToStruct( files, "name" );

loop array=st index="local.item"{
systemOutput( item, true );
}

arrayAppend( tests, _file( dir, "644.txt", "644" ) );
arrayAppend( tests, _file( dir, "743.txt", "743" ) );
arrayAppend( tests, _file( dir, "043.txt", "443" ) );
arrayAppend( tests, _file( dir, "400.txt", "400" ) );

var files = directoryList( dir, true, "query");
var st = QueryToStruct( files, "name" );

loop collection=st item="local.item"{
systemOutput( item, true );
}
loop array=tests item="local.test" {
systemOutput( test, true );
}
loop array=tests item="local.test" {
systemOutput( test, true );
var key = mid( test.name, len( dir ) + 1 );
systemOutput( key, true );
expect( st ).toHaveKey( key );
systemOutput( st[ key ], true );
expect( test.mode ).toBe( st[ key ].mode );
}

});
} );
}

private function _dir( parent, name, mode ){
var dir = parent & name;
directoryCreate( dir );
fileSetAccessMode( dir, mode );
return {
name: dir,
mode: mode,
type: "dir"
};
}

private function _file( parent, name, mode ){
var file = parent & name;
fileWrite( file, "" );
fileSetAccessMode( file, mode );
return {
name: file,
mode: mode,
type: "file"
};
}

private function isNotUnix(){
return (server.os.name == "windows");
}

}
110 changes: 110 additions & 0 deletions test/tickets/LDEV5034.cfc
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
component extends="org.lucee.cfml.test.LuceeTestCase" {

function beforeAll(){
variables.dir = getTempDirectory() & "LDEV-5034/";
if ( directoryExists( dir ) )
directoryDelete( dir, true );
directoryCreate( dir );
};

function afterAll(){
if ( directoryExists( dir ) ){
directoryDelete( dir, true );
};
};

function run( testResults, testBox ){
describe( "fileSetAccessMode", function(){
it( title="test access modes", skip=isNotUnix(), body=function(){
var tests = [];

arrayAppend( tests, _dir( dir, "755", "755" ) );
arrayAppend( tests, _dir( dir, "777", "777" ) );
arrayAppend( tests, _dir( dir, "644", "644" ) );

var files = directoryList( dir, true, "query");
var st = QueryToStruct( files, "name" );

loop array=st index="local.item"{
systemOutput( item, true );
}

arrayAppend( tests, _file( dir, "644.txt", "644" ) );
arrayAppend( tests, _file( dir, "743.txt", "743" ) );
arrayAppend( tests, _file( dir, "043.txt", "443" ) );
arrayAppend( tests, _file( dir, "400.txt", "400" ) );

var files = directoryList( dir, true, "query");
var st = QueryToStruct( files, "name" );

loop collection=st item="local.item"{
systemOutput( item, true );
}
loop array=tests item="local.test" {
systemOutput( test, true );
}
loop array=tests item="local.test" {
systemOutput( test, true );
var key = mid( test.name, len( dir ) + 1 );
systemOutput( key, true );
expect( st ).toHaveKey( key );
systemOutput( st[ key ], true );
expect( test.mode ).toBe( st[ key ].mode );
}

var tar = getTempFile( getTempDirectory(), "LDEV-5034", ".tar.gz" );
compress( "tgz", dir, tar );

var dest = getTempDirectory() & "LDEV-5034-" & createUUID() & "/";
if ( directoryExists( dest ) );
directoryDelete( dest, true );
directoryCreate( dest );
extract( "tgz", tar, dest );

var extractedFiles = directoryList( dest, true, "query" );
var st2 = QueryToStruct( files, "name" );
loop collection=st2 item="local.item"{
systemOutput( item, true );
}

expect( files.recordcount ).toBe( extractedFiles.recordcount );

loop array=tests item="local.test" {
systemOutput( test, true );
var key = mid( test.name, len( dest) + 1 );
expect( st ).toHaveKey( key );
systemOutput( st[ key ], true );
expect( test.mode ).toBe( st[ key ].mode, test.name );
}

});
} );
}

private function _dir( parent, name, mode ){
var dir = parent & name;
directoryCreate( dir );
fileSetAccessMode( dir, mode );
return {
name: dir,
mode: mode,
type: "dir"
};
}

private function _file( parent, name, mode ){
var file = parent & name;
fileWrite( file, "" );
fileSetAccessMode( file, mode );
return {
name: file,
mode: mode,
type: "file"
};
}

private function isNotUnix(){
return (server.os.name == "windows");
}

}

0 comments on commit 60897bc

Please sign in to comment.