Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use dockerized Fuseki for PHPUnit tests #1496

Merged
merged 5 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
key: fuseki-${{ hashFiles('tests/init_fuseki.sh') }}

- name: Start up Fuseki
run: cd tests; sh ./init_fuseki.sh
run: cd tests; ./init_fuseki.sh

- name: Cache Composer dependencies
uses: actions/cache@v3
Expand Down
17 changes: 8 additions & 9 deletions dockerfiles/Dockerfile.ubuntu
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ubuntu:20.04
FROM ubuntu:22.04

LABEL maintainer="National Library of Finland"
LABEL version="0.1"
Expand All @@ -7,19 +7,18 @@ LABEL description="A Docker image for Skosmos with Apache httpd."
ARG DEBIAN_FRONTEND=noninteractive

# git is necessary for some composer packages e.g. davidstutz/bootstrap-multiselect
# gettext is necessary as php-gettext was available in 18.04, but not in 20.04
RUN apt-get update && apt-get install -y \
apache2 \
curl \
gettext \
git \
libapache2-mod-php7.4 \
libapache2-mod-php8.1 \
locales \
php7.4 \
php7.4-curl \
php7.4-xsl \
php7.4-intl \
php7.4-mbstring \
php8.1 \
php8.1-curl \
php8.1-xsl \
php8.1-intl \
php8.1-mbstring \
php-apcu \
php-zip \
unzip \
Expand Down Expand Up @@ -53,7 +52,7 @@ ENV LC_ALL=en_US.UTF-8
ENV LANG=en_US.UTF-8

# timezone
RUN sed -i 's/;date.timezone =/date.timezone = "UTC"/g' /etc/php/7.4/apache2/php.ini
RUN sed -i 's/;date.timezone =/date.timezone = "UTC"/g' /etc/php/8.1/apache2/php.ini

COPY dockerfiles/config/000-default.conf /etc/apache2/sites-available/000-default.conf

Expand Down
2 changes: 1 addition & 1 deletion dockerfiles/config/skosmos.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

:tdb_dataset_readwrite rdf:type tdb2:DatasetTDB2 ;
tdb2:location "/fuseki/databases/skosmos" ;
# tdb2:unionDefaultGraph true ;
tdb2:unionDefaultGraph true ;
.

<#indexLucene> rdf:type text:TextIndexLucene ;
Expand Down
2 changes: 1 addition & 1 deletion tests/ModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public function testGetVocabularyByGraphUri()
public function testGetVocabularyByInvalidGraphUri()
{
$this->expectException(ValueError::class);
$this->expectExceptionMessage("no vocabulary found for graph http://no/address and endpoint http://localhost:13030/skosmos-test/sparql");
$this->expectExceptionMessage("no vocabulary found for graph http://no/address and endpoint http://localhost:9030/skosmos/sparql");
$vocab = $this->model->getVocabularyByGraph('http://no/address');
$this->assertInstanceOf('Vocabulary', $vocab);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/VocabularyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function testGetEndpoint()
{
$vocab = $this->model->getVocabulary('testdiff');
$endpoint = $vocab->getEndpoint();
$this->assertEquals('http://localhost:13030/skosmos-test/sparql', $endpoint);
$this->assertEquals('http://localhost:9030/skosmos/sparql', $endpoint);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// make sure that a SPARQL endpoint is set by an environment variable
$endpoint = getenv('SKOSMOS_SPARQL_ENDPOINT');
if (!$endpoint) {
// default to Fuseki running on localhost:13030 as provided by init_fuseki.sh
putenv('SKOSMOS_SPARQL_ENDPOINT=http://localhost:13030/skosmos-test/sparql');
// default to Fuseki running on localhost:9030 as provided by init_fuseki.sh
putenv('SKOSMOS_SPARQL_ENDPOINT=http://localhost:9030/skosmos/sparql');
}

# Allow running git commands in the php-actions/phpunit container
Expand Down
41 changes: 10 additions & 31 deletions tests/init_fuseki.sh
Original file line number Diff line number Diff line change
@@ -1,37 +1,16 @@
#!/bin/bash
# Note: This script must be sourced from within bash, e.g. ". init_fuseki.sh"

FUSEKI_VERSION=${FUSEKI_VERSION:-4.4.0}
# Build and start up containers (skosmos, skosmos-cache, fuseki)
cd ../dockerfiles
docker compose up -d --build

if [ "$FUSEKI_VERSION" = "SNAPSHOT" ]; then
# find out the latest snapshot version and its download URL by parsing Apache directory listings
snapshotdir="https://repository.apache.org/content/repositories/snapshots/org/apache/jena/apache-jena-fuseki/"
latestdir=$(wget -q -O- "$snapshotdir" | grep 'a href=' | cut -d '"' -f 2 | grep SNAPSHOT | tail -n 1)
FUSEKI_VERSION=$(basename "$latestdir")
fusekiurl=$(wget -q -O- "$latestdir" | grep 'a href=' | cut -d '"' -f 2 | grep '\.tar\.gz$' | tail -n 1)
else
fusekiurl="https://repository.apache.org/content/repositories/releases/org/apache/jena/apache-jena-fuseki/$FUSEKI_VERSION/apache-jena-fuseki-$FUSEKI_VERSION.tar.gz"
fi
# FIXME: should check that it's up instead of blindly waiting 5 seconds
echo "Waiting for Fuseki to get ready"
sleep 5

if [ ! -f "apache-jena-fuseki-$FUSEKI_VERSION/fuseki-server" ]; then
echo "fuseki server file not found - downloading it"
wget --no-verbose --output-document=fuseki-dist.tar.gz "$fusekiurl"
echo "uncompressing fuseki distribution"
tar -zxf fuseki-dist.tar.gz
fi

cd "apache-jena-fuseki-$FUSEKI_VERSION"
chmod +x fuseki-server bin/s-put
./fuseki-server --port=13030 --config ../fuseki-assembler.ttl &
until curl --output /dev/null --silent --head --fail http://localhost:13030; do
printf '.'
sleep 2
done

for fn in ../test-vocab-data/*.ttl; do
for fn in ../tests/test-vocab-data/*.ttl; do
name=$(basename "${fn}" .ttl)
$(./bin/s-put http://localhost:13030/skosmos-test/data "http://www.skosmos.skos/$name/" "$fn")
echo "Loading test vocabulary $name"
curl -I -X POST -H Content-Type:text/turtle -T "$fn" -G http://localhost:9030/skosmos/data --data-urlencode graph="http://www.skosmos.skos/$name/"
echo
done

cd ..

2 changes: 1 addition & 1 deletion tests/testconfig.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

:config a skosmos:Configuration ;
# SPARQL endpoint defaults to $SKOSMOS_SPARQL_ENDPOINT environment var
# skosmos:sparqlEndpoint <http://localhost:13030/skosmos-test/sparql> ;
# skosmos:sparqlEndpoint <http://localhost:9030/skosmos/sparql> ;
# sparql-query extension, or "Generic" for plain SPARQL 1.1
# set to "JenaText" instead if you use Fuseki with jena-text index
# skosmos:sparqlDialect "JenaText" ;
Expand Down