|
From: <jgr...@us...> - 2003-11-10 20:15:31
|
Update of /cvsroot/popfile/engine/tests
In directory sc8-pr-cvs1:/tmp/cvs-serv4335/tests
Modified Files:
TestConfiguration.tst TestPOP3.tst TestProxy.tst
Log Message:
"Unixification of POPFile"
--------------------------
1. Change command line parsing to use Getopt so that in future
we can have real command line options. In the past an option
was equivalent to a configuration file item. So you could set
module_param value
inside popfile.cfg, but you could also to
popfile.pl -module_param value
on the command line. The new form of the latter is
popfile.pl --set module_param=value
For the ultimate in laziness you can also use the old style
if you precede the first old style parameter with --, e.g.
the old style command line above would work in the new scheme
if specified as follows
popfile.pl -- -module_param value
It is still even possible to use very old style parameters
from pre-OO days of POPFile with the addition of the --
popfile.pl -- -ui_port 8080
2. Make it possible for a module to disable itself and hence be
unloaded. Unloadable modules have an 'enabled' paramter (currently
supported by all proxies (POP3, NNTP and SMTP) and XML-RPC). If
this parameter is 0 then use if to return the value '2' from start()
which indicates to Loader that the module wishes to be removed.
POPFile/Configuration.pm:
Use Getopt to handle new style command line options. Make
parse_command_line return 0 if there's an error.
POPFile/Module.pm:
Update documentation on start().
POPFile/Loader.pm:
Check the return code from start() and if it is 2 unload the module.
Check the return code from parse_command_line so we halt if there's an
error in command-line parsing.
Proxy/Proxy.pm:
Initialize the 'enabled' parameter to 1.
Proxy/POP3.pm
Proxy/SMTP.pm
Proxy/NNTP.pm:
Use the 'enabled' parameter to return 2 from start() so that if we
are not enabled we get unloaded. Also if not enabled don't register
any UI components.
UI/XMLRPC.pm:
Use the 'enabled' parameter to return 2 from start() so that if we
are not enabled we get unloaded. Also if not enabled don't register
any UI components.
Classifier/Bayes.pm:
When classifying a message without saving to disk, still add the
XPL link.
tests.pl:
Code layout clean up.
tests/TestConfiguration.pm:
Update and improve tests for command-line parsing.
tests/TestProxy.pm:
Check for the initial setting of the 'enabled' parameter.
tests/TestPOP3.pm:
Check that the enabled parameter is interpreted by start() to mean
no start and return 2. Make the XTP tests less time sensitive.
Index: TestConfiguration.tst
===================================================================
RCS file: /cvsroot/popfile/engine/tests/TestConfiguration.tst,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** TestConfiguration.tst 8 Sep 2003 18:03:57 -0000 1.8
--- TestConfiguration.tst 10 Nov 2003 20:15:22 -0000 1.9
***************
*** 199,230 ****
# Check command line parsing
! @ARGV = ( '-config_piddir', 'test2/' );
! $c->parse_command_line();
test_assert_equal( $c->module_config_( 'config', 'piddir' ), 'test2/' );
! @ARGV = ( 'config_piddir', 'test3/' );
open (STDERR, ">stdout.tmp");
! $c->parse_command_line();
close STDERR;
open OUTPUT, "<stdout.tmp";
my $line = <OUTPUT>;
close OUTPUT;
! test_assert_regexp( $line, 'Expected a command line option and got config_piddir' );
! test_assert_equal( $c->module_config_( 'config', 'piddir' ), 'test2/' );
! @ARGV = ( '-config_piddir' );
open (STDERR, ">stdout.tmp");
! $c->parse_command_line();
close STDERR;
open OUTPUT, "<stdout.tmp";
my $line = <OUTPUT>;
close OUTPUT;
! test_assert_regexp( $line, 'Missing argument for -config_piddir' );
! test_assert_equal( $c->module_config_( 'config', 'piddir' ), 'test2/' );
! @ARGV = ( '-config_foobar' );
open (STDERR, ">stdout.tmp");
! $c->parse_command_line();
close STDERR;
open OUTPUT, "<stdout.tmp";
my $line = <OUTPUT>;
close OUTPUT;
! test_assert_regexp( $line, 'Unknown command line option -config_foobar' );
--- 199,237 ----
# Check command line parsing
! @ARGV = ( '--set', '-config_piddir=test2/' );
! test_assert( $c->parse_command_line() );
test_assert_equal( $c->module_config_( 'config', 'piddir' ), 'test2/' );
! @ARGV = ( '--set', 'config_piddir=test3/' );
! test_assert( $c->parse_command_line() );
! test_assert_equal( $c->module_config_( 'config', 'piddir' ), 'test3/' );
! @ARGV = ( '--', '-config_piddir' );
open (STDERR, ">stdout.tmp");
! test_assert( !$c->parse_command_line() );
close STDERR;
open OUTPUT, "<stdout.tmp";
+ <OUTPUT>;
my $line = <OUTPUT>;
close OUTPUT;
! test_assert_regexp( $line, 'Missing argument for -config_piddir' );
! test_assert_equal( $c->module_config_( 'config', 'piddir' ), 'test3/' );
! @ARGV = ( '--', '-config_foobar' );
open (STDERR, ">stdout.tmp");
! test_assert( !$c->parse_command_line() );
close STDERR;
open OUTPUT, "<stdout.tmp";
+ <OUTPUT>;
my $line = <OUTPUT>;
close OUTPUT;
! test_assert_regexp( $line, 'Unknown option -config_foobar' );
! @ARGV = ( '--', '-config_piddir', 'test4/' );
! test_assert( $c->parse_command_line() );
! test_assert_equal( $c->module_config_( 'config', 'piddir' ), 'test4/' );
! @ARGV = ( '--doesnotexist', '-config_piddir', 'test4/' );
open (STDERR, ">stdout.tmp");
! test_assert( !$c->parse_command_line() );
close STDERR;
open OUTPUT, "<stdout.tmp";
my $line = <OUTPUT>;
close OUTPUT;
! test_assert_regexp( $line, 'Unknown option: doesnotexist' );
Index: TestPOP3.tst
===================================================================
RCS file: /cvsroot/popfile/engine/tests/TestPOP3.tst,v
retrieving revision 1.17
retrieving revision 1.18
diff -C2 -d -r1.17 -r1.18
*** TestPOP3.tst 10 Nov 2003 19:55:36 -0000 1.17
--- TestPOP3.tst 10 Nov 2003 20:15:24 -0000 1.18
***************
*** 387,391 ****
$p->config_( 'force_fork', 1 );
$p->global_config_( 'timeout', 1 );
! $p->start();
while ( 1 ) {
--- 387,395 ----
$p->config_( 'force_fork', 1 );
$p->global_config_( 'timeout', 1 );
!
! $p->config_( 'enabled', 0 );
! test_assert_equal( $p->start(), 2 );
! $p->config_( 'enabled', 1 );
! test_assert_equal( $p->start(), 1 );
while ( 1 ) {
***************
*** 779,783 ****
$result = <$client>;
$result =~ s/popfile2=8/popfile0=0/;
! test_assert_equal( $result, $line );
if ( $headers == 0 ) {
$countdown -= 1;
--- 783,787 ----
$result = <$client>;
$result =~ s/popfile2=8/popfile0=0/;
! test_assert_equal( $result, $line, "[$result][$line]" );
if ( $headers == 0 ) {
$countdown -= 1;
***************
*** 973,977 ****
while ( <FILE> ) {
my $line = $_;
! $result = <$client>;
$result =~ s/popfile3=1/popfile0=0/;
test_assert_equal( $result, $line );
--- 977,987 ----
while ( <FILE> ) {
my $line = $_;
! while ( $result = <$client> ) {
! if ( $result =~ /TimeoutPrevention/ ) {
! next;
! } else {
! last;
! }
! }
$result =~ s/popfile3=1/popfile0=0/;
test_assert_equal( $result, $line );
Index: TestProxy.tst
===================================================================
RCS file: /cvsroot/popfile/engine/tests/TestProxy.tst,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -d -r1.16 -r1.17
*** TestProxy.tst 13 Oct 2003 20:23:41 -0000 1.16
--- TestProxy.tst 10 Nov 2003 20:15:24 -0000 1.17
***************
*** 97,100 ****
--- 97,102 ----
$p->logger( $l );
+ test_assert_equal( $p->config_( 'enabled' ), 1 );
+
# Start a generic proxy on port 9999
my $port = 9000 + int(rand(1000));
|