1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
#!/usr/bin/perl -w
#
# Test that we can remove .rpm files from our cache.
#
# Steve
# --
use strict;
use File::Temp;
use Test::More qw( no_plan );
#
# Find our script
#
my $script = undef;
$script = "./bin/rinse" if ( -e "./bin/rinse" );
$script = "../bin/rinse" if ( -e "../bin/rinse" );
ok( $script, "We found our script" );
#
# Create a random directory
#
my $dir = File::Temp::tempdir( CLEANUP => 1 );
ok( -d $dir, "The temporary directory exists" );
#
# Populate the tree with RPM files.
#
createRPMS( $dir );
#
# Count the RPM files.
#
my $count = countRPM( $dir );
ok( $count, "We have some RPM files: $count" );
#
# Delete the cache
#
system( "perl $script --cache-dir=$dir --clean-cache" );
#
# Count them again
#
$count = countRPM( $dir );
is( $count, 0, "The RPM files are all correctly removed!" );
sub createRPMS
{
my( $dir ) = ( @_ );
my @rand = qw/ foo bar baz bart steve /;
foreach my $f ( sort( @rand ) )
{
`touch $dir/$f.rpm`;
ok( -e "$dir/$f.rpm", "Created random RPM file $f.rpm" );
}
}
sub countRPM
{
my( $dir ) = ( @_ );
my $count = 0;
foreach my $file ( sort( glob( $dir . "/*.rpm" ) ) )
{
$count += 1;
}
return $count;
}
|