diff options
-rw-r--r-- | NEWS | 6 | ||||
-rw-r--r-- | README | 60 | ||||
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | tests/initdb.at | 5 | ||||
-rw-r--r-- | tests/initdb.c | 32 | ||||
-rw-r--r-- | tests/testsuite.at | 5 |
6 files changed, 81 insertions, 29 deletions
@@ -1,13 +1,13 @@ -vmod-dbrw -- history of user-visible changes. 2013-07-20 +vmod-dbrw -- history of user-visible changes. 2014-11-12 Copyright (C) 2013-2014 Sergey Poznyakoff See the end of file for copying conditions. Please send vmod-dbrw bug reports to <gray@gnu.org> -Version 1.9.90, (git) +Version 1.9.91, (git) -Builds for both Varnish v3.x and v4.x +Supports both Varnish 3.x and v4.x Version 1.0, 2013-07-20 @@ -137,18 +137,22 @@ This will build the module. Finally, do the following command as root: * Testing Testing the module requires access to an SQL database which will be -populated with the test data. You can either create the database -and SQL user, or just an SQL user and give him rights for creating it. -For example: +populated with the test data. Before running the test suite, you +have to create the database, or the user (role), which is able to +create it. For example, for MySQL: GRANT ALL PRIVILEGES on dbrw_test.* to dbrw_test@localhost; +Or, for PostgreSQL: + + CREATE ROLE dbrw_test WITH LOGIN CREATEDB + Once done, supply the SQL credentials and the database name with -extra arguments to configure, as shown in the example below: +extra arguments to `make check', as shown in the example below: - ./configure --with-varnish-source=/usr/src/varnish-3.0.1\ - DBRW_TEST_DATABASE=dbrw_test\ - DBRW_TEST_USER=dbrw_test + make DBRW_TEST_DBTYPE=mysql\ + DBRW_TEST_DATABASE=dbrw_test\ + DBRW_TEST_USER=dbrw_test check You can use the following variables: @@ -184,15 +188,47 @@ Database user. Password to connect to the server (if necessary). -After running make, do +Ideally, the tests should succeed. If they don't, that don't +necessarily indicates a problem in the module: + +The tests will be skipped if the supplied credentials are insufficient +to access the SQL server. + +If the first test fails, and all subsequent ones are marked as +"expected failure", that means that the testsuite wasn't able to +create or populate the test database. You will find more info in the +file named FAILURE located in the tests directory. Fix the problem, +run `make -C tests clean' (see below) and re-run `make check'. + +If all tests are marked as "expected failure", then the testsuite +uses the cached data from the previous run, which wasn't able to +create or populate the test database. In this case, act as described +above. +Finally, if some or all of the tests were marked as failed, that +indicates a bug in the module itself, or in the test suite. In this +case, the file testsuite.log will contain detailed logs. Additional +information can then be found in the directory testsuite.dir. Please +send these data to the developer. + +Notice that the testsuite tries to create the database only once. +Subsequent invocations of `make check' will use the existing database. +Similarly, if it failed to create the database, the failure will be +memorized and all subsequent runs will just skip all checks. To clear +the state, run `make clean' in the directory tests, e.g.: + + make -C tests clean make check -to run the tests. Ideally, they should succeed. The tests will be skipped -if the supplied credentials are insufficient to access the SQL server. -If they fail, the file testsuite.log will contain detailed logs. -Additional information can then be found in the directory testsuite.dir. +You can also supply the database credentials in invocation of +configure: + + ./configure --with-varnish-source=/usr/src/varnish-3.0.1\ + DBRW_TEST_DATABASE=dbrw_test\ + DBRW_TEST_USER=dbrw_test +This way you won't need to supply them to `make check'. + * Bug reporting Send bug reports and suggestions to <gray@gnu.org> diff --git a/configure.ac b/configure.ac index db494c4..4508f76 100644 --- a/configure.ac +++ b/configure.ac @@ -14,7 +14,7 @@ # You should have received a copy of the GNU General Public License # along with vmod-dbrw. If not, see <http://www.gnu.org/licenses/>. AC_PREREQ(2.69) -AC_INIT([vmod-dbrw], 1.9.90, [gray@gnu.org]) +AC_INIT([vmod-dbrw], 1.9.91, [gray@gnu.org]) AC_CONFIG_AUX_DIR([build-aux]) AC_CONFIG_MACRO_DIR([m4]) AC_CONFIG_SRCDIR(src/vmod_dbrw.vcc) diff --git a/tests/initdb.at b/tests/initdb.at index d158664..25e43f7 100644 --- a/tests/initdb.at +++ b/tests/initdb.at @@ -38,10 +38,11 @@ CREATE TABLE rewrite ( dest varchar(255) DEFAULT NULL, value varchar(255) DEFAULT NULL, pattern varchar(255) DEFAULT NULL, - flags varchar(64) DEFAULT NULL, - KEY source (host,url) + flags varchar(64) DEFAULT NULL ); +CREATE INDEX source ON rewrite(host,url); + INSERT INTO rewrite VALUES ('en.example.net','/local','http://uno.example.com/remote',NULL,NULL,NULL), ('en.example.net','/local/%','http://dos.example.com/$[]1','$url','/local/(.*)',NULL), diff --git a/tests/initdb.c b/tests/initdb.c index 16ac968..a92f880 100644 --- a/tests/initdb.c +++ b/tests/initdb.c @@ -133,15 +133,26 @@ trycreate(struct dbrw_connection *conn, const char *dbname) if (strcmp(conn->conf->backend->name, "mysql") == 0) { snprintf(q, sizeof q, "CREATE DATABASE IF NOT EXISTS %s", dbname); + if (sql_query(conn, q)) { + dbrw_error("query failed: %s", q); + exit(4); + } } else { snprintf(q, sizeof q, - "IF NOT EXISTS (SELECT 1 FROM pg_database WHERE datname = '%s') THEN\n" - " CREATE DATABASE %s\n" - "END IF", dbname, dbname); - } - if (sql_query(conn, q)) { - dbrw_error("query failed: %s", q); - exit(4); + "SELECT datname FROM pg_database WHERE datname='%s'", + dbname); + if (sql_query(conn, q)) { + dbrw_error("query failed: %s", q); + exit(4); + } + if (sql_num_tuples(conn) == 0) { + snprintf(q, sizeof q, "CREATE DATABASE %s", + dbname); + if (sql_query(conn, q)) { + dbrw_error("query failed: %s", q); + exit(4); + } + } } } @@ -211,8 +222,11 @@ main(int argc, char **argv) dbname = cfg.param[i]; for (; cfg.param[i+1]; i++) cfg.param[i] = cfg.param[i + 1]; - cfg.param[i] = NULL; - + if (strcmp(cfg.backend->name, "pgsql") == 0) { + cfg.param[i] = "database=postgres"; + cfg.param[i + 1] = NULL; + } else + cfg.param[i] = NULL; } s = findparam(cfg.param, "debug"); diff --git a/tests/testsuite.at b/tests/testsuite.at index aafef83..5858b6a 100644 --- a/tests/testsuite.at +++ b/tests/testsuite.at @@ -25,11 +25,12 @@ m4_include([initdb.at]) m4_define([AT_DBINIT_PREREQ],[dnl AT_DBCRED_PREREQ -AT_SKIP_IF(test -f $FAILFILE) +AT_XFAIL_IF(test -f $FAILFILE) +test -f $FAILFILE && exit 1 ]) m4_define([AT_DBRW_INIT],[ -if ! test -f $INITFILE; then +if ! test -f $INITFILE && ! test -f $FAILFILE; then AT_DBRW_INITDB fi ]) |