Footprintless

 view release on metacpan or  search on metacpan

t/Footprintless_App_Command_overlay.t  view on Meta::CPAN

    }

    $logger->debugf( 'checking %s', $got_file );
    is( slurp($got_file), $original_content, "$action: $file matches expected" );
}

sub test_overlay {
    my ( $coordinate, $action, %options ) = @_;

    my $temp_dir = File::Temp->newdir();
    my $overlay_dir = File::Spec->catdir( $temp_dir, 'overlay' );
    make_path($overlay_dir);

    my $footprintless = footprintless( $temp_dir, $overlay_dir );
    my $overlay = $footprintless->entities()->get_entity($coordinate);

    unless ( $overlay->{base_dir} eq File::Spec->catfile( $test_dir, 'data', 'base' )
        && $overlay->{template_dir} eq File::Spec->catfile( $test_dir, 'data', 'template' )
        && $overlay->{to_dir} =~ /^$overlay_dir/ )
    {
        ;
        $logger->errorf(
            "%s=[%s]\n%s=[%s]\n%s starts with [%s]", $overlay->{base_dir},
            File::Spec->catfile( $test_dir, 'data', 'base' ),     $overlay->{template_dir},
            File::Spec->catfile( $test_dir, 'data', 'template' ), $overlay->{to_dir},
            $overlay_dir
        );
        BAIL_OUT('environment configuration broken, could be dangerous to proceed...');
    }
    $logger->debug('environment looks good, proceed...');

    if ( $logger->is_trace ) {
        $logger->tracef( 'overlay: %s', Data::Dumper->new( [$overlay] )->Indent(1)->Dump() );
    }

    Footprintless::App::clear_pretend_self();
    my $result = test_app(
        'Footprintless::App' => [
            'overlay', $coordinate,
            $action, ( $options{command_args} ? @{ $options{command_args} } : () )
        ]
    );
    is( $result->exit_code(), 0, "overlay completed succesfully" );
    if ( $logger->is_debug() ) {
        $logger->debugf(
            "exit_code=[%s],error=[%s]\n----- STDOUT ----\n%s\n---- STDERR ----\n%s\n---- END ----",
            $result->exit_code(), $result->error(), $result->stdout(), $result->stderr()
        );
    }

    &{ $options{validator} }($footprintless) if ( $options{validator} );
}

my $coordinate = 'dev.foo.overlay';
test_overlay(
    $coordinate,
    'update',
    validator => sub {
        my ($footprintless) = @_;
        match( 'bin/catalina.sh',         $footprintless, $coordinate, 'update' );
        match( 'bin/setenv.sh',           $footprintless, $coordinate, 'update' );
        match( 'conf/jndi-resources.xml', $footprintless, $coordinate, 'update' );
        match( 'conf/server.xml',         $footprintless, $coordinate, 'update' );
    }
);

test_overlay(
    $coordinate,
    'initialize',
    validator => sub {
        my ($footprintless) = @_;

        match( 'bin/catalina.sh',          $footprintless, $coordinate, 'initialize' );
        match( 'bin/setenv.sh',            $footprintless, $coordinate, 'initialize' );
        match( 'conf/jndi-resources.xml',  $footprintless, $coordinate, 'initialize' );
        match( 'conf/server.xml',          $footprintless, $coordinate, 'initialize' );
        match( 'conf/catalina.properties', $footprintless, $coordinate, 'initialize' );
    }
);



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