| 1 | package Test::BDD::Infrastructure::Filesystem; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 1 | our $VERSION = '1.005'; # VERSION | |||||||||
| 7 | # ABSTRACT: cucumber step definitions for checking file systems | ||||||||||
| 8 | |||||||||||
| 9 | 1 | ▶ | use Test::More; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 1 | ▶ | use Test::BDD::Cucumber::StepFile qw( Given When Then ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 0 | ▶ | sub S { Test::BDD::Cucumber::StepFile::S } | ||||||||
|
Subroutine
S: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 13 | |||||||||||
| 14 | 1 | ▶ | use Test::BDD::Infrastructure::Utils qw( | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | 1 | convert_unit convert_cmp_operator $CMP_OPERATOR_RE convert_interval); | |||||||||
| 16 | |||||||||||
| 17 | |||||||||||
| 18 | 1 | ▶ | use IPC::Run; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 19 | |||||||||||
| 20 | 0 | ▶ | sub check_df_ok { | ||||||||
|
Subroutine
check_df_ok: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 21 | 0 | my $path = shift; | |||||||||
| 22 | 0 | my @cmd = ( 'df', '-P', '-T' ); | |||||||||
| 23 | 0 | my ( $in, $out, $err ); | |||||||||
| 24 | 0 | my $stats = { | |||||||||
| 25 | path => $path, | ||||||||||
| 26 | }; | ||||||||||
| 27 | 0 | my $ret = IPC::Run::run( \@cmd, \$in, \$out, \$err ); | |||||||||
| 28 | 0 | ▶ | if( ! $ret ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 29 | 0 | fail('error running df: '.$err); | |||||||||
| 30 | 0 | return; | |||||||||
| 31 | } | ||||||||||
| 32 | 0 | my @lines = split("\n", $out); | |||||||||
| 33 | 0 | shift @lines; # remove header | |||||||||
| 34 | |||||||||||
| 35 | 0 | @$stats{'device', 'type', 'blocks', 'used space', 'free space', 'usage', 'mount point'} | |||||||||
| 36 | = split(/\s+/, $lines[0]); | ||||||||||
| 37 | 0 | $stats->{'used space'} *= 1024; | |||||||||
| 38 | 0 | $stats->{'free space'} *= 1024; | |||||||||
| 39 | 0 | $stats->{'usage'} =~ s/%$//; | |||||||||
| 40 | 0 | $stats->{'usage'} /= 100; | |||||||||
| 41 | 0 | $stats->{'size'} = $stats->{'used space'} + $stats->{'free space'}; | |||||||||
| 42 | |||||||||||
| 43 | 0 | return( $stats ); | |||||||||
| 44 | } | ||||||||||
| 45 | |||||||||||
| 46 | 0 | ▶ | Given qr/a filesystem is mounted on (.*)$/, sub { | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 47 | 0 | my $path = $1; | |||||||||
| 48 | |||||||||||
| 49 | 0 | ▶ | if( ! -e $path ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 50 | 0 | fail("the file $path does not exist"); | |||||||||
| 51 | } | ||||||||||
| 52 | 0 | S->{'fs'} = check_df_ok( $path ); | |||||||||
| 53 | 1 | }; | |||||||||
| 54 | |||||||||||
| 55 | 0 | ▶ | Then qr/the filesystems? (device|type|mount point) must be(?: like)? (.*)$/, sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 56 | 0 | like(S->{'fs'}->{$1}, qr/$2/, "the $1 must be like $2"); | |||||||||
| 57 | 1 | }; | |||||||||
| 58 | 0 | ▶ | Then qr/the filesystems? (device|type|mount point) must be(?: unlike|not like)? (.*)$/, sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 59 | 0 | unlike(S->{'fs'}->{$1}, qr/$2/, "the $1 must be unlike $2"); | |||||||||
| 60 | 1 | }; | |||||||||
| 61 | |||||||||||
| 62 | 0 | ▶ | Then qr/the filesystems? (blocks|size|used space|free space|usage) must be $CMP_OPERATOR_RE (\d+) (\S+)?/, sub { | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 63 | 0 | my $key = $1; | |||||||||
| 64 | 0 | my $op = convert_cmp_operator( $2 ); | |||||||||
| 65 | 0 | my $count = $3; | |||||||||
| 66 | 0 | ▶ | if( defined $4 ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 67 | 0 | $count = convert_unit( $3, $4 ); | |||||||||
| 68 | } | ||||||||||
| 69 | 0 | cmp_ok( S->{'fs'}->{$key}, $op, $count, "the filesystems $key $op $count"); | |||||||||
| 70 | 1 | }; | |||||||||
| 71 | |||||||||||
| 72 | 1 | 1; | |||||||||
| 73 | |||||||||||
| 74 | __END__ | ||||||||||