Skip to content

Commit

Permalink
Refactor test scripts and improve documentation comments
Browse files Browse the repository at this point in the history
  • Loading branch information
iwphonedo committed Jan 8, 2025
1 parent 30809a7 commit a3f892a
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 32 deletions.
2 changes: 1 addition & 1 deletion tests/fixtures/policy_stores.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import pytest
from images import cedar_image, opa_image
from testcontainers.core.network import Network

from tests.containers.cedar_container import CedarContainer
from tests.containers.opa_container import OpaContainer, OpaSettings
from tests.containers.settings.cedar_settings import CedarSettings
from tests.fixtures.images import cedar_image, opa_image


@pytest.fixture(scope="session")
Expand Down
2 changes: 2 additions & 0 deletions tests/genopalkeys.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# This is utility script to generate OPAL keys - Use it for your needs

# This function generates a pair of RSA keys using ssh-keygen, extracts the public key into OPAL_AUTH_PUBLIC_KEY,
# formats the private key by replacing newlines with underscores and stores it in OPAL_AUTH_PRIVATE_KEY,
# and then removes the key files. It outputs messages indicating the start and completion of key generation.
Expand Down
7 changes: 4 additions & 3 deletions tests/install_opal.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# This is a helper script to install opal-server and opal-client

# Installs opal-server and opal-client using pip.
# If the installation fails or the commands are not available,
# it exits with an error message.
# Installs opal-server and opal-client using pip.
# If the installation fails or the commands are not available,
# it exits with an error message.

function install_opal_server_and_client {
echo "- Installing opal-server and opal-client from pip..."
Expand Down
26 changes: 0 additions & 26 deletions tests/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,8 @@ if [[ -f ".env" ]]; then
source .env
fi


# Deletes pytest-generated .env files so they don't interfere with other tests.
function cleanup {

PATTERN="pytest_[a-f,0-9]*.env"
echo "Looking for auto-generated .env files matching pattern '$PATTERN'..."

for file in $PATTERN; do
if [[ -f "$file" ]]; then
echo "Deleting file: $file"
rm "$file"
else
echo "No matching files found for pattern '$PATTERN'."
break
fi
done

echo "Cleanup complete!\n"
}

function main {

# Cleanup before starting, maybe some leftovers from previous runs
cleanup

echo "Running tests..."

# Check if a specific test is provided
Expand All @@ -43,9 +20,6 @@ function main {
fi

echo "Done!"

# Cleanup at the end
cleanup
}

main "$@"
9 changes: 7 additions & 2 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,13 @@ def build_docker_image(docker_file: str, image_name: str, session_matrix: dict):
image = docker_client.images.get(image_name)

if not image:
# context_path=os.path.join(os.path.dirname(__file__), ".."), # Expands the context
context_path = ".."
if "tests" in os.path.abspath(__file__):
logger.info(f"Right now the file is {os.path.abspath(__file__)}")
context_path = os.path.abspath(
os.path.join(os.path.dirname(__file__), "..", "..", "opal")
)
else:
context_path = ".."
dockerfile_path = os.path.join(os.path.dirname(__file__), "docker", docker_file)
logger.info(f"Context path: {context_path}, Dockerfile path: {dockerfile_path}")

Expand Down

0 comments on commit a3f892a

Please sign in to comment.