0

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.

manually creating docker container

asked Jul 9, 2024 at 20:05
5
  • Looks like you don't have a cypher function. Does this help? Commented Jul 10, 2024 at 5:35
  • The setup_age.sql is used to enable it. But it is not enabling. If I do it manually it works, with the bash script, it does not. Commented Jul 10, 2024 at 16:50
  • From the bash viewpoint, I don't see anything problematic. Don't know enough about docker and postgres to say whether there could be a problem there. If you say that it manually works, I have to ask you to do the following: First, enter the commands from your script manually in your bash shell (copy&paste) and make a screenshot of the output; then execute the script using bash -x SCRIPTNAME and make a screenshot of the output. Post both screenshots .... there must be something we are missing. Commented Jul 11, 2024 at 10:43
  • @user1934428 I have added the output of the bash script. Commented Jul 12, 2024 at 23:26
  • The screenshot shows the interactive session. There is no screenshot showing the bash -x command and its output. Please add this as well. Commented Jul 14, 2024 at 8:37

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.