Run a command on the node, then verify that $expected_sql appears in the
server log file.
-Reads the whole log file so be careful when working with large log outputs.
-The log file is truncated prior to running the command, however.
-
=cut
sub issues_sql_like
local $ENV{PGHOST} = $self->host;
local $ENV{PGPORT} = $self->port;
- truncate $self->logfile, 0;
+ my $log_location = -s $self->logfile;
+
my $result = TestLib::run_log($cmd);
ok($result, "@$cmd exit code 0");
- my $log = TestLib::slurp_file($self->logfile);
+ my $log = TestLib::slurp_file($self->logfile, $log_location);
like($log, $expected_sql, "$test_name: SQL found in server log");
return;
}
use Config;
use Cwd;
use Exporter 'import';
-use Fcntl qw(:mode);
+use Fcntl qw(:mode :seek);
use File::Basename;
use File::Find;
use File::Spec;
if ($windows_os)
{
require Win32API::File;
- Win32API::File->import(qw(createFile OsFHandleOpen CloseHandle));
+ Win32API::File->import(qw(createFile OsFHandleOpen CloseHandle setFilePointer));
}
# Specifies whether to use Unix sockets for test setups. On
=pod
-=item slurp_file(filename)
+=item slurp_file(filename [, $offset])
-Return the full contents of the specified file.
+Return the full contents of the specified file, beginning from an
+offset position if specified.
=cut
sub slurp_file
{
- my ($filename) = @_;
+ my ($filename, $offset) = @_;
local $/;
my $contents;
if ($Config{osname} ne 'MSWin32')
{
open(my $in, '<', $filename)
or die "could not read \"$filename\": $!";
+ if (defined($offset))
+ {
+ seek($in, $offset, SEEK_SET)
+ or die "could not seek \"$filename\": $!";
+ }
$contents = <$in>;
close $in;
}
or die "could not open \"$filename\": $^E";
OsFHandleOpen(my $fh = IO::Handle->new(), $fHandle, 'r')
or die "could not read \"$filename\": $^E\n";
+ if (defined($offset))
+ {
+ setFilePointer($fh, $offset, qw(FILE_BEGIN))
+ or die "could not seek \"$filename\": $^E\n";
+ }
$contents = <$fh>;
CloseHandle($fHandle)
or die "could not close \"$filename\": $^E\n";