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.
*Edit [2024年07月12日]: Included the output of the script.
Using default tag: latest
latest: Pulling from apache/age
Digest: sha256:5134806b5de7d16e0123fba928f7992064b4eebaeb9f2cae225ad4f5b5475a33
Status: Image is up to date for apache/age:latest
docker.io/apache/age:latest
What's Next?
View a summary of image vulnerabilities and recommendations → docker scout quickview apache/age
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
7bbe43007dbac2185ef6da73e4e503e61deade3651f470c04611c6531c41a3f0
Successfully copied 2.05kB to myPostgresDb:/setup_age.sql
LOAD
SET
Screenshot showing that it works when manually creating the docker container and executing the query inside it.
cypherfunction. Does this help?setup_age.sqlis used to enable it. But it is not enabling. If I do it manually it works, with the bash script, it does not.bash -x SCRIPTNAMEand make a screenshot of the output. Post both screenshots .... there must be something we are missing.bash -xcommand and its output. Please add this as well.