Skip to content
Snippets Groups Projects
Select Git revision
  • 0f9684ecee0bdabf24d2dcff8fd2cc36b7f67eb6
  • master default protected
2 results

configure_iptables_external.yml

Blame
  • 03-report.t 2.40 KiB
    use v5.36;
    use Test::Cmd;
    use Test::More tests =>18;
    use Path::Tiny;
    my $perl = $^X;
    my $testapp = Test::Cmd->new(
        prog        => path(__FILE__)->parent->parent->child('bin')->child('ta-tool.pl'),
        workdir     => '',
        subdir      => 'bin',
        #verbose     => 1,
        interpreter => "$perl -I lib/ ",
    );
    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 $cache_dir = path($testapp->workpath())->child('.cache');
    $cache_dir->mkpath();
    my $cache_file = $cache_dir->child('ta-tool.cache');
    $config_file->spew_utf8(<<_CFG_);
    ---
    elasticsearch_host: sdvlzaamtestfotothek01.slub-dresden.de
    elasticsearch_port: 9200
    http_only: 1
    logdir: /tmp
    password: 839852bed005a7f1237578a6ac1197c142f7d0dd58bb248446dc7849d4bf770902e7f980ad83d39008ad638bc41e2345
    user: lza
    _CFG_
    # tests
    note "help check";
    foreach my $param ("help report", "report -h", "report --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");
    }
    
    note "check cli params";
    $testapp->run(args =>'report');
    #say "STDOUT:",$testapp->stdout;
    #say "STDERR:",$testapp->stderr;
    like($testapp->stdout, qr/^:lang: en\n:date:.*\n:generator:.*\n== Report from.*\n=== count/s, 'ta-tool report, base, stdout');
    like($testapp->stderr, qr/^reporting for period/s, 'ta-tool report, base, stderr');
    is($? >> 8, 0, 'ta-tool report, base, exit status');
    
    $testapp->run(args =>'report --output-as-csv');
    #say "STDOUT:",$testapp->stdout;
    #say "STDERR:",$testapp->stderr;
    like($testapp->stdout, qr/^"set","subset","aip_state","flavour","value"\n"([a-z]+)",,"([a-z]+)","([a-z]+)",\d+(\.\d+)?\n/s, 'ta-tool report, base, stdout');
    like($testapp->stderr, qr/^reporting for period/s, 'ta-tool report, base, stderr');
    is($? >> 8, 0, 'ta-tool report, base, exit status');
    
    note "overrides";
    $testapp->run(args =>'report --elasticsearch-host localhost');
    #say "STDOUT:",$testapp->stdout;
    #say "STDERR:",$testapp->stderr;
    like($testapp->stdout, qr/^$/s, 'ta-tool report, base, stdout');
    like($testapp->stderr, qr/^Hint: override local config with/s, 'ta-tool report, base, stderr');
    is($? >> 8, 111, 'ta-tool report, base, exit status');