GlusterFS-GFAPI-FFI
view release on metacpan or search on metacpan
t/lib/TestFile.pm view on Meta::CPAN
sub shutdown : Test(shutdown)
{
my $self = shift;
$self->{fd}->_set_fd(undef);
}
sub test_validate_init : Test(2)
{
my $self = shift;
throws_ok {
GlusterFS::GFAPI::FFI::File->new();
} qr/I\/O operation on invalid fd/;
throws_ok {
GlusterFS::GFAPI::FFI::File->new(fd => 'not_int');
} qr/I\/O operation on invalid fd/;
}
sub test_fchmod_success : Test
{
my $self = shift;
my $mock_glfs_fchmod = sub {
return 0;
};
no warnings 'redefine';
my $glfs_fchmod = \&GlusterFS::GFAPI::FFI::glfs_fchmod;
${GlusterFS::GFAPI::FFI::}{glfs_fchmod} = $mock_glfs_fchmod;
ok(!$self->{fd}->fchmod(mode => 0600), '$f->fchmod() is returned with 0');
${GlusterFS::GFAPI::FFI::}{glfs_fchmod} = $glfs_fchmod;
}
sub test_fchmod_fail_exception : Test
{
my $self = shift;
my $mock_glfs_fchmod = sub {
return -1;
};
no warnings 'redefine';
my $glfs_fchmod = \&GlusterFS::GFAPI::FFI::glfs_fchmod;
${GlusterFS::GFAPI::FFI::}{glfs_fchmod} = $mock_glfs_fchmod;
throws_ok {
$self->{fd}->fchmod(mode => 0600);
} qr/glfs_fchmod\(${\$self->{fd}->fd}, 0600\) failed/;
${GlusterFS::GFAPI::FFI::}{glfs_fchmod} = $glfs_fchmod;
}
sub test_fchown_success : Test
{
my $self = shift;
my $mock_glfs_fchown = sub {
return 0;
};
no warnings 'redefine';
my $glfs_fchown = \&GlusterFS::GFAPI::FFI::glfs_fchown;
${GlusterFS::GFAPI::FFI::}{glfs_fchown} = $mock_glfs_fchown;
ok(!$self->{fd}->fchown(uid => 9, gid => 11)
, '$f->fchown(uid => 9, gid => 11) is returned with 0');
${GlusterFS::GFAPI::FFI::}{glfs_fchown} = $glfs_fchown;
}
sub test_fchown_exception : Test
{
my $self = shift;
my $mock_glfs_fchown = sub {
return -1;
};
no warnings 'redefine';
my $glfs_fchown = \&GlusterFS::GFAPI::FFI::glfs_fchown;
${GlusterFS::GFAPI::FFI::}{glfs_fchown} = $mock_glfs_fchown;
throws_ok {
$self->{fd}->fchown(uid => 9, gid => 11);
} qr/glfs_fchown\(${\$self->{fd}->fd}, 9, 11\) failed/;
${GlusterFS::GFAPI::FFI::}{glfs_fchown} = $glfs_fchown;
}
sub test_dup : Test(3)
{
my $self = shift;
my $mock_glfs_dup = sub {
return 2;
};
no warnings 'redefine';
my $glfs_dup = \&GlusterFS::GFAPI::FFI::glfs_dup;
${GlusterFS::GFAPI::FFI::}{glfs_dup} = $mock_glfs_dup;
my $dup_f = $self->{fd}->dup();
isa_ok($dup_f, 'GlusterFS::GFAPI::FFI::File'
, '$f->dup() is returned with GlusterFS::GFAPI::FFI::File instance');
cmp_ok($dup_f->originalpath, 'eq', 'fakefile'
, '$dup_f->originalpath is "fakefile"');
cmp_ok($dup_f->fd, '==', 2, '$dup_f->fd is "2"');
${GlusterFS::GFAPI::FFI::}{glfs_dup} = $glfs_dup;
}
sub test_fdatasync_success : Test
{
my $self = shift;
my $mock_glfs_fdatasync = sub {
return 4;
};
no warnings 'redefine';
my $glfs_fdatasync = \&GlusterFS::GFAPI::FFI::glfs_fdatasync;
${GlusterFS::GFAPI::FFI::}{glfs_fdatasync} = $mock_glfs_fdatasync;
cmp_ok($self->{fd}->fdatasync(), '==', 4, '$f->fdatasync() is returned with 4');
${GlusterFS::GFAPI::FFI::}{glfs_fdatasync} = $glfs_fdatasync;
}
sub test_fdatasync_fail_exception : Test
{
my $self = shift;
my $mock_glfs_fdatasync = sub {
return -1;
};
no warnings 'redefine';
my $glfs_fdatasync = \&GlusterFS::GFAPI::FFI::glfs_fdatasync;
( run in 0.430 second using v1.01-cache-2.11-cpan-71847e10f99 )