App-Smbxfer

 view release on metacpan or  search on metacpan

t/xfer_essentials.t  view on Meta::CPAN

#
# Careful tests of the essentials, namely upload/download...
#
use strict;

use Test::More tests => 9;
use Test::Differences qw( eq_or_diff );

use Filesys::SmbClient;

use IO::Prompt;
use File::Find;
use File::Temp qw( tempdir );

BEGIN { use_ok( 'App::Smbxfer', qw( smb_element_type parse_smb_spec do_smb_transfer ) ) }

#~~~~ ((( begin test initialization ))) ~~~~
    prompt( "\n...Beginning test... <press ENTER> " );
    my $server =    prompt( "\n\nSamba server name? " );
    my $share =     prompt( "share name? " );
    my $domain =    prompt( "domain? " );
    my $username =  prompt( "username? " );
    my $password =  prompt( "password? ", -e => '*' );
    my $path_file = prompt( "enter the path to any existing file on the share (relative to share root): " );
    my $path_dir =  prompt( "enter the path to any existing directory on the share (relative to share root): " );
    
    my $smb_share_spec = "smb://$server/$share";

    my $smb = Filesys::SmbClient->new(
        username => $username, password => $password, workgroup => $domain
    );

    # name of dir that will be uploaded as a test:
    my $local_dirname_to_upload = 'dir_to_upload';
    # local relative path to directory containing test resources:
    my $local_path_to_test_resources = 't/test_resources';
    my $local_path_to_upload = "$local_path_to_test_resources/$local_dirname_to_upload";
    # name of temp dir to create at root of SMB share:
    my $remote_smbxfer_dirname = 'smbxfer_test';
    my $remote_smbxfer_path_spec = $smb_share_spec . '/' . $remote_smbxfer_dirname;

    # Make dir for testing...
    $smb->mkdir( $remote_smbxfer_path_spec, '0666' )
        or die "SMB error: cannot mkdir for testing: $!";

    # Future 'die()'s should clean up after tests before really 'die()'ing
    $SIG{__DIE__} = sub { cleanup( $smb, $remote_smbxfer_path_spec ); die @_ };
#~~~~ ((( end test initialization ))) ~~~~


#
# smb_element_type() tests...
#
TODO: {
    local $TODO = 'Find out why this behaves differently in different environments; may be related to different versions of libsmbclient.so';

    is( smb_element_type( $smb, $smb_share_spec          ), SMBC_FILE_SHARE, "detected element type: share" );
}
is( smb_element_type( $smb, "$smb_share_spec/$path_file" ), SMBC_FILE,       "detected element type: file" );
is( smb_element_type( $smb, "$smb_share_spec/$path_dir"  ), SMBC_DIR,        "detected element type: dir" );


#
# parse_smb_spec()
#
ok( my ($smb_share_path, $smb_path_spec) = (parse_smb_spec( $smb_share_spec ))[3,5], "parse share spec" );



( run in 0.562 second using v1.01-cache-2.11-cpan-0b5f733616e )