Skip to content

Commit

Permalink
Add support for running tests inside container
Browse files Browse the repository at this point in the history
WIP, there are still some tests failing. Need more investigation.
  • Loading branch information
xcompass committed Jan 22, 2024
1 parent a897540 commit 6f40c10
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 2 deletions.
1 change: 1 addition & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ services:
context: .
expose:
- 9000
container_name: hotcrp
restart: always
volumes:
- ./docker/msmtprc:/etc/msmtprc
Expand Down
22 changes: 22 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,25 @@ Keycloak:
MariaDB:
* Root: `root`/`root`
* HotCRP: `hotcrp`/`hotcrppwd`

Tests
-----

To run tests in container, follow the steps below:
```bash
# create a port forwarding in hotcrp container to mysql as some of the places for db host are hardcoded as localhost
docker run --rm --name mysql-bridge --net=container:hotcrp alpine/socat TCP-LISTEN:3306,fork TCP:mysql:3306

# enter to the hotcrp container
docker exec -it hotcrp bash

# install db client
apt update && apt install -y mariadb-client procps

# create databases, users and schemas. use 127.0.0.1 to trigger mysql client to use tcp instead of socket and grant hotcrp.% host privileges.
lib/createdb.sh -u root -proot -c test/options.php --batch --host 127.0.0.1 --grant-host hotcrp.% --replace
lib/createdb.sh -u root -proot -c test/cdb-options.php --no-dbuser --batch --host 127.0.0.1 --grant-host hotcrp.% --replace

# run the tests
test/check.sh --all
```
2 changes: 1 addition & 1 deletion lib/createdb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ set_dbuserpass () {
}

add_granthost () {
if expr "$1" : '[-a-zA-Z0-9.*][-a-zA-Z0-9.*]*$' >/dev/null; then
if expr "$1" : '^[.%_a-zA-Z0-9-]*$' >/dev/null; then
granthosts="$granthosts $1"
else
echo "Expected --grant-host=HOSTNAME" 1>&2
Expand Down
1 change: 1 addition & 0 deletions test/cdb-options.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
$Opt["dbName"] = "hotcrp_testdb_cdb";
$Opt["dbUser"] = "hotcrp_testdb";
$Opt["dbPassword"] = "m5LuaN23j26g";
$Opt["dbHost"] = "127.0.0.1";
$Opt["shortName"] = "Testconf I";
$Opt["longName"] = "Test Conference I";
$Opt["contactName"] = "Eddie Kohler";
Expand Down
3 changes: 2 additions & 1 deletion test/options.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
global $Opt;
$Opt["dbName"] = "hotcrp_testdb";
$Opt["dbPassword"] = "m5LuaN23j26g";
$Opt["dbHost"] = "127.0.0.1";
$Opt["shortName"] = "Testconf I";
$Opt["longName"] = "Test Conference I";
$Opt["paperSite"] = "http://hotcrp.lcdf.org/test/";
Expand All @@ -16,6 +17,6 @@
$Opt["smartScoreCompare"] = true;
$Opt["timezone"] = "America/New_York";
$Opt["postfixEOL"] = "\n";
$Opt["contactdbDsn"] = "mysql://hotcrp_testdb:m5LuaN23j26g@localhost/hotcrp_testdb_cdb";
$Opt["contactdbDsn"] = "mysql://hotcrp_testdb:m5LuaN23j26g@127.0.0.1/hotcrp_testdb_cdb";
$Opt["obsoletePasswordInterval"] = 1;
$Opt["include"][] = "?test/localoptions.php";

0 comments on commit 6f40c10

Please sign in to comment.