Skip to content
Snippets Groups Projects
Select Git revision
  • e15c4ead98c30fefd115c7b5daf9610b964e3f8c
  • master default protected
  • diag
  • version1.3-archivematica
  • version1.2-archivematica
  • version1.1-archivematica
  • version1.0-archivematica
  • version1.0-rosetta
8 results

02-init.t

Blame
  • 02-init.t 2.89 KiB
    #!perl
    use v5.36;
    use Test::Cmd;
    use Test::More tests =>6;
    use Test::TA;
    use Path::Tiny;
    my $testapp = Test::TA::testapp();
    if ( $ENV{_} !~ /dzil/) { # patch if not dzil
        $ENV{'TEST_ACTIVE'} = 1;
        delete $ENV{PERL_MM_USE_DEFAULT};
        local $ENV{'HOME'} = $testapp->workpath();
    }
    my $config_dir = path($testapp->workpath())->child('.config');
    $config_dir->mkpath();
    my $config_file = $config_dir->child('ta-tool.rc');
    my $testhost = Test::TA::testhost();
    my $testport = Test::TA::testport();
    my $cache_dir = path($testapp->workpath())->child('.cache');
    $cache_dir->mkpath();
    my $cache_file = $cache_dir->child('ta-tool.cache');
    my $permanent_path = path($testapp->workpath)->child('permanent');
    my @permanent_volumes = map { $permanent_path->child($_); } qw(foo bar);
    
    # tests
    use_ok("SLUB::LZA::TA::Crypt");
    is(SLUB::LZA::TA::Crypt::encrypt("199fc76b9d086d8937976634e93413bcd005d941"), "839852bed005a7f1237578a6ac1197c142f7d0dd58bb248446dc7849d4bf770902e7f980ad83d39008ad638bc41e2345", "ta-tool, init, check encryption");
    is(SLUB::LZA::TA::Crypt::decrypt("839852bed005a7f1237578a6ac1197c142f7d0dd58bb248446dc7849d4bf770902e7f980ad83d39008ad638bc41e2345"), "199fc76b9d086d8937976634e93413bcd005d941", "ta-tool, init, check encryption");
    ok($testapp, "init 'ta-tool'");
    
    subtest 'help check' => sub {
        plan tests => 9;
        foreach my $param ("help init", "init -h", "init --help") {
            $testapp->run(args => $param);
            #say "STDOUT:",$testapp->stdout;
            #say "STDERR:",$testapp->stderr;
            like($testapp->stdout, qr/this usage screen/, "ta-tool $param, stdout");
            like($testapp->stderr, qr/^$/, "ta-tool $param, stderr");
            is($? >> 8, 0, "ta-tool $param, exit status");
        }
    };
    
    subtest 'init check' => sub {
        plan tests => 6;
        $testapp->run(
            stdin => <<_EOF_,
    lza
    199fc76b9d086d8937976634e93413bcd005d941
    199fc76b9d086d8937976634e93413bcd005d941
    _EOF_
            args  => 'init -D -v -e ' . $testhost .join("", map {" -P $_"} @permanent_volumes),
            #args  => 'init -e sdvlzaamtestfotothek01.slub-dresden.de -l /tmp',
        );
        #say "STDOUT:",$testapp->stdout;
        #say "STDERR:",$testapp->stderr;
        like($testapp->stdout, qr/User:.*store config in /s, 'ta-tool init, stdout');
        like($testapp->stderr, qr/HINT:/, 'ta-tool init, stderr');
        unlike($testapp->stderr, qr/Error/, 'ta-tool init, stderr indicates no error');
        is($? >> 8, 0, 'ta-tool init, exit status');
        my $config = $config_file->slurp_utf8();
        is($config, <<_EXP_, "ta-tool init, config file as expected");
    ---
    elasticsearch_host: $testhost
    elasticsearch_port: $testport
    http_only: 1
    logdir: /tmp
    password: 839852bed005a7f1237578a6ac1197c142f7d0dd58bb248446dc7849d4bf770902e7f980ad83d39008ad638bc41e2345
    permanent_volume:
      - $permanent_volumes[0]
      - $permanent_volumes[1]
    user: lza