From 548578c8c96d304fb777c9aeb233733f97145818 Mon Sep 17 00:00:00 2001 From: David Steele Date: Sun, 17 Nov 2013 13:58:21 -0500 Subject: [PATCH] Working on unit test. --- .gitignore | 2 ++ pg_backrest.pl | 17 ++++++++++++++++ test/test.pl | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+) create mode 100644 .gitignore create mode 100644 pg_backrest.pl create mode 100755 test/test.pl diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..ebec8ba8c --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +**/*~ +*~ diff --git a/pg_backrest.pl b/pg_backrest.pl new file mode 100644 index 000000000..12efcfac9 --- /dev/null +++ b/pg_backrest.pl @@ -0,0 +1,17 @@ +#!/usr/bin/perl + +#use Getopt::Long; + +sub execute +{ + local($strCommand) = @_; + my $strOutput; + + print("$strCommand\n"); + $strOutput = qx($strCommand) or return 0; + print("$strOutput\n"); + + return 1; +} + + \ No newline at end of file diff --git a/test/test.pl b/test/test.pl new file mode 100755 index 000000000..27ad6bb1c --- /dev/null +++ b/test/test.pl @@ -0,0 +1,54 @@ +#!/usr/bin/perl + +#use strict; + +my $strPgBinPath = '/usr/lib/postgresql/9.3/bin/'; + +sub execute +{ + local($strCommand) = @_; + my $strOutput; + + print("$strCommand\n"); + $strOutput = qx($strCommand) or return 0; + print("$strOutput\n"); + + return 1; +} + +sub pg_create +{ + local($strPath) = @_; + + execute($strPgBinPath . "initdb -D $strPath -A trust"); + execute("mkdir $strPath/archive"); +} + +sub pg_start +{ + local($strPath) = @_; + my $strCommand = $strPgBinPath . "pg_ctl start -o \"-c wal_level=archive -c archive_mode=on -c archive_command='test ! -f $strPath/archive/%f && cp %p $strPath/archive/%f'\" -D $strPath -l $strPath/postgresql.log -w -s"; + + execute($strCommand); +} + +sub pg_stop +{ + local($strPath) = @_; + my $strCommand = $strPgBinPath . "pg_ctl stop -D $strPath -w -s"; + + execute($strCommand); +} + +sub pg_drop +{ + local($strPath) = @_; + my $strCommand = "rm -rf $strPath"; + + execute($strCommand); +} + +pg_stop("/home/dsteele/test/test2"); +pg_drop("/home/dsteele/test/test2"); +pg_create("/home/dsteele/test/test2"); +pg_start("/home/dsteele/test/test2");