diff --git a/testing/.gitignore b/testing/.gitignore new file mode 100644 index 00000000..402eee67 --- /dev/null +++ b/testing/.gitignore @@ -0,0 +1 @@ +regression-conf.php.dynamic.per-test diff --git a/testing/dav_test b/testing/dav_test index cefea0ac..2b1c4c00 100755 --- a/testing/dav_test +++ b/testing/dav_test @@ -90,6 +90,14 @@ my $request_id_file = "$save_location/$case.request_id"; open(my $REQUEST_ID_FILE, "> $request_id_file") || die "Failed to open $request_id_file for writing"; +# Allow for application configuration per test file. Ensure the file we +# manage is empty in case the previous test was aborted. +my $dynamic_app_conf_file = 'regression-conf.php.dynamic.per-test'; +if (-f $dynamic_app_conf_file) { + unlink $dynamic_app_conf_file + || die "Failed to remove $dynamic_app_conf_file\n"; +} + my $datafile = $testdef; $datafile =~ s{\.test$}{}; push @arguments, "--header", 'X-DAViCal-Testcase: '.$datafile; @@ -98,13 +106,14 @@ $datafile .= '.data'; my $state = ""; my $data_binary; -my $sql_variable = ""; +my $sql_variable = ""; my $sql_statement = ""; +my $sql_values = {}; my $perl_code = ""; -my $sql_values = {}; -my $queries = (); +my $app_conf = ""; +my $queries = (); my $replacements = (); -my $line_number = 0; +my $line_number = 0; open( TEST, '<', $testdef ) or die "Can't open '$testdef'"; @@ -119,7 +128,7 @@ while( ) { } if ( $state ne "" ) { - $line =~ /^BEGIN(DATA|PERL)/ && do { + $line =~ /^BEGIN(?!:)/ && do { print "Found a new BEGIN line, while still processing a previous one. Line number: $line_number\n"; exit 0; }; @@ -141,6 +150,9 @@ while( ) { exit 0; } } + elsif ( $state eq "APPCONF" ) { + write_app_conf($app_conf); + } $state = ""; } elsif ( $state eq "DATA" ) { @@ -152,6 +164,9 @@ while( ) { elsif ( $state eq "PERL" ) { $perl_code .= $line; } + elsif ( $state eq "APPCONF" ) { + $app_conf .= $line; + } next; } @@ -226,6 +241,11 @@ while( ) { $state = "PERL"; }; + $line =~ /^BEGINAPPCONF\s*$/ && do { + $app_conf = ""; + $state = "APPCONF"; + }; + $line =~ /^(?:BEGIN)?GETSQL\s*=\s*(\S.*)$/ && do { $sql_variable = $1; $sql_statement = ""; @@ -237,6 +257,26 @@ while( ) { $state = "DOSQL"; }; + $line =~ /^\s*APPCONF\s*=\s*(\S.*)$/ && do { + my $basename = $1; + my $test_app_conf_file; + + if ( -e "tests/$suite/$basename.appconf" ) { + $test_app_conf_file="tests/$suite/$basename.appconf"; + } + elsif ( -e "tests/$suite/$basename" ) { + $test_app_conf_file="tests/$suite/$basename"; + } + + if (! defined $test_app_conf_file) { + die "Can't find app conf file $basename or $basename.appconf"; + } + + copy $test_app_conf_file, $dynamic_app_conf_file + || die "Failed to copy $test_app_conf_file to $dynamic_app_conf_file: $!\n"; + }; + + $line =~ /^REPLACE\s*=\s*(\S)(.*)$/ && do { my $separator = $1; $2 =~ /^([^$separator]*)$separator([^$separator]*)$separator$/ && do { @@ -506,6 +546,22 @@ sub webui_login { return $mech; } +=item write_app_conf() + +Write per test configuration entries to the DAViCal regression test server +configuration. + +=cut + +sub write_app_conf { + my $content = shift; + + # We may wany to append extra content to a common file. + open(my $FILE, ">> $dynamic_app_conf_file") + || die "Failed to open $dynamic_app_conf_file for writing"; + print $FILE $content; +} + sub usage { print </.data' exists the contents of that file will be sent in the body of the request. diff --git a/testing/regression-conf.php.example b/testing/regression-conf.php.example index de2348e3..00d20355 100644 --- a/testing/regression-conf.php.example +++ b/testing/regression-conf.php.example @@ -69,4 +69,6 @@ 'cal._domainkey.caldav' => 'v=DKIM1; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEArTRqr/W5wSlxDKthes0Bz2fIkukLOu0tNIbxO9GpsjgaE3juPnl9XlkMxvkGQ5k7NTy2yRIYDFqDzT150MiMLsIbOnXlOZVizlM8MXe65do6BNCnjNZRNj30pEHirhJsQf0eEc9+AY1qDbC2axqd1Nf8MNl0bJ58O0ZCPnzdDNxsWp16midWoj0uceonpg1qxp7kYD2CC5/WcrsBHc8Lt3y2N9X4pamAvd0fAfVXYrzLSVvmc1b09yEq3weT4R4Jiizjb7UPPZCyarDDOUKfjcBsPCJtBDv7al6easoCUvHviJKy48bmcFcgnyL1FfKVdIaKlyb3nLj9dFTFm/tdTQIDAQAB', ); + // Allow dynamic configuration of application by tests. + include 'regression-conf.php.dynamic.per-test'; ?>