App-Fetchware

 view release on metacpan or  search on metacpan

t/bin-fetchware-upgrade-all.t  view on Meta::CPAN

# Only those who run fetchware's own author tests will have
# FETCHWARE_NONROOT_USER set when the test suite runs. So most users will get an
# annoying uninitialized warning from this. Also, this will set the user config
# file option to the empty string, which fetchware most likely considers similar
# to undef so that probably doesn't cause any weird bugs. To deal with this
# situation, I'll just set it here to nobody, which is otherwise the default
# anyway.
#
# Other options are to have if statements everywhere FETCHWARE_NONROOT_USER is
# used. Something like.
#
#    if (defined $ENV{FETCHWARE_NONROOT_USER}) {
#    my $test_dist_path = make_test_dist(file_name => 'test-dist',
#        ver_num => '1.00',
#        append_option => qq{user '$ENV{FETCHWARE_NONROOT_USER}';});
#    } else {
#        my $test_dist_path = make_test_dist(file_name => 'test-dist',
#            ver_num => '1.00');
#    }
# But that's fugly, and adds annoying code duplication. I know my test suite was
# created with loads of copy and paste, but that doesn't mean this kind of
# garbage code is okay. I'd kill for like a line oriented, smart (meaning fixes
# obvious syntax errors for you) ifdef system where I could just if def this
# argument, where only if FETCHWARE_NONROOT_USER was defined this stupid
# argument would be added. Do Perl 6 macros do this???
$ENV{FETCHWARE_NONROOT_USER} = 'nobody' if not defined $ENV{FETCHWARE_NONROOT_USER};
 

subtest 'test cmd_upgrade_all() success' => sub {
    skip_all_unless_release_testing();

    my $apache_fetchwarefile = <<EOF;
use App::Fetchware;

program 'Apache 2.2';

lookup_url '$ENV{FETCHWARE_LOCAL_UPGRADE_URL}';

mirror '$ENV{FETCHWARE_LOCAL_UPGRADE_URL}';

filter 'httpd-2.2';

# user needed when root, because nobody won't haver permissions to access local
# user's directory where the local files above for loookup_url and mirror are.
user 'dly';
EOF


    my $ctags_fetchwarefile = <<EOF;
use App::Fetchware;

program 'ctags';

lookup_url '$ENV{FETCHWARE_LOCAL_UPGRADE_URL}';

mirror '$ENV{FETCHWARE_LOCAL_UPGRADE_URL}';

filter 'ctags';

# Disable verification, because ctags provides none.
verify_failure_ok 'On';

# user needed when root, because nobody won't haver permissions to access local
# user's directory where the local files above for loookup_url and mirror are.
user 'dly';
EOF

    my @fetchware_packages;
    for my $fetchwarefile ($apache_fetchwarefile, $ctags_fetchwarefile) {
note('FETCHWAREFILE');
note("$fetchwarefile");
        my $package_name = $fetchwarefile;
        $package_name =~ /(httpd-2\.2|ctags)/; 
        $package_name = $1;
note("packagename[$package_name]");
        my $fetchwarefile_path = create_test_fetchwarefile($fetchwarefile);

        ok(-e $fetchwarefile_path,
            'check create_test_fetchwarefile() test Fetchwarefile');

        # I obviously must install apache before I can test upgrading it :)
        push @fetchware_packages, cmd_install($fetchwarefile_path);
        # And then test if the install was successful.
        ok(grep /$package_name/, glob(catfile(fetchware_database_path(), '*')),
            'check cmd_install(Fetchware) success.');

        # Clear internal %CONFIG variable, because I have to parse a Fetchwarefile
        # twice, and it's only supported once.
        __clear_CONFIG();
    }


    # upgrade_all: Copy over new version of ctags too.
    # Also copy over the latest version of httpd, so that I don't have to change
    # the lookup_url in the Fetchwarefile of the httpd fetchware package.
    # httpd copy stuff.
    my $striped_upgrade_path = $ENV{FETCHWARE_LOCAL_UPGRADE_URL};
    $striped_upgrade_path =~ s!^file://!!;
    my $parent_upgrade_path = dir($striped_upgrade_path)->parent();
    my $httpd_upgrade = catfile($parent_upgrade_path, 'httpd-2.2.22.tar.bz2');
    my $httpd_upgrade_asc = catfile($parent_upgrade_path,
        'httpd-2.2.22.tar.bz2.asc');
note("httpd_upgrade[$httpd_upgrade] stripedupgradepath[$striped_upgrade_path]");
    ok(cp($httpd_upgrade, $striped_upgrade_path),
        'checked cmd_upgrade() cp new version  httpd to local upgrade url');
note("httpd_upgrade_asc[$httpd_upgrade_asc]");
    ok(cp($httpd_upgrade_asc, $striped_upgrade_path),
        'checked cmd_upgrade() cp new version httpd asc to local upgrade url');
    # ctags copy stuff.
    my $ctags_upgrade = catfile($parent_upgrade_path, 'ctags-5.8.tar.gz');
note("ctags_upgrade[$ctags_upgrade]");
    ok(cp($ctags_upgrade, $striped_upgrade_path),
        'checked cmd_upgrade() cp new version ctags to local upgrade url');


    # upgrade all packages, which will test if upgrading everything in
    # fetchware_database_path works.
    my @upgraded_package_paths = cmd_upgrade_all();
    note("HERE");
    note explain \@upgraded_package_paths;



( run in 0.452 second using v1.01-cache-2.11-cpan-39bf76dae61 )