I am developing a python module that uses Apache AGE and I want to do some unit testing. For this, I wrote a bash script that runs the container, copies a SQL configuration file to it, executes the SQL query, runs some tests written in python, and then stops and removes the container. All this is done so that I can check for errors faster.
test_script.sh:
#!/bin/bash
# Set the Apache AGE container running.
docker pull apache/age
docker run
--name myPostgresDb
-p 5455:5432
-e POSTGRES_USER=postgresUser
-e POSTGRES_PASSWORD=postgresPW
-e POSTGRES_DB=postgresDB
-d
apache/age
sleep 3
# Copy the SQL script into the container.
docker cp tests/setup_age.sql myPostgresDb:/setup_age.sql
sleep 1
# Execute the SQL script inside the container.
docker exec -i myPostgresDb psql -U postgresUser -d postgresDB -f /setup_age.sql
sleep 1
# Execute the Python test script.
python3 -m tests.test
docker stop myPostgresDb
docker rm myPostgresDb
setup_age.sql
LOAD 'age';
SET search_path = ag_catalog, "$user", public;
The problem is that, even if the SQL script runs correctly, when one of the tests on the python test script runs the query:
SELECT * FROM cypher('graph', $$
CREATE (n:label)
$$) as (n agtype);
it does not recognizes the cypher function:
psycopg2.errors.UndefinedFunction: function cypher(unknown, unknown) does not exist
LINE 2: SELECT * FROM cypher('graph', $$
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
When running an interactive terminal session inside the container and executing the setup query and the test query, it works fine, but it is not automated and this process takes some time.