From 1fc8384073996627938ccabdefc30b7ee4ea6267 Mon Sep 17 00:00:00 2001 From: Daniil Tkachev Date: Thu, 9 Jan 2025 12:40:52 +0100 Subject: [PATCH] TC-47 test cypress --- .github/oxid-esales/cypress.sh | 56 +++++++++++----------------------- 1 file changed, 18 insertions(+), 38 deletions(-) diff --git a/.github/oxid-esales/cypress.sh b/.github/oxid-esales/cypress.sh index 17d7f0c..c8ddc48 100755 --- a/.github/oxid-esales/cypress.sh +++ b/.github/oxid-esales/cypress.sh @@ -38,15 +38,11 @@ EOF if ! grep -q "networks:" docker-compose.yml; then echo "$app_network" >> docker-compose.yml echo "Custom network added to docker-compose.yml." - else - echo "Custom network already exists in docker-compose.yml." fi if ! grep -q "cypress:" docker-compose.yml; then echo "$cypress_service" >> docker-compose.yml echo "Cypress service added successfully." - else - echo "Cypress service already exists in docker-compose.yml." fi else echo "Error: docker-compose.yml not found." @@ -54,52 +50,36 @@ EOF fi } -function wait_for_service_health() { - local service_name=$1 - echo "Waiting for $service_name to be healthy..." - local retries=20 - local count=0 - - while [ $count -lt $retries ]; do - if docker inspect --format '{{if .State.Health}}{{.State.Health.Status}}{{else}}no_health_check{{end}}' $service_name | grep -q "healthy"; then - echo "$service_name is healthy." - return 0 - fi - echo "Waiting for $service_name to be healthy... ($count/$retries)" - count=$((count + 1)) - sleep 5 - done +function add_network_to_services() { + echo "Injecting custom network into existing services in docker-compose.yml..." - echo "Error: $service_name failed to become healthy." - return 1 + if grep -q "apache:" docker-compose.yml && grep -q "php:" docker-compose.yml; then + sed -i '/apache:/,/[^ ]/{s/volumes:/&\n networks:\n - app-network/}' docker-compose.yml + sed -i '/php:/,/[^ ]/{s/volumes:/&\n networks:\n - app-network/}' docker-compose.yml + echo "Custom network injected into existing services." + else + echo "Error: Services apache or php not found in docker-compose.yml." + exit 1 + fi } function run_docker_compose_up() { - cat docker-compose.yml echo "Running docker-compose up..." + docker-compose config # Validate the YAML file docker compose up --build -d apache php -# wait_for_service_health telecash-module-apache-1 || exit 1 + echo "Waiting for services to start..." + sleep 10 # Adjust as needed - echo "Curl-ing Apache from Cypress container" + echo "Starting Cypress container..." + docker compose up --build -d cypress + docker ps + + echo "Testing connectivity..." if ! docker exec -it telecash-module-cypress-1 curl -I http://telecash-module-apache-1; then echo "Error: Unable to reach Apache from Cypress container." exit 1 fi - - docker compose up cypress -} - -function add_network_to_services() { - echo "Injecting custom network into existing services in docker-compose.yml..." - - if grep -q "services:" docker-compose.yml; then - sed -i '/services:/a \ apache:\n networks:\n - app-network\n php:\n networks:\n - app-network' docker-compose.yml - echo "Custom network injected into services." - else - echo "Error: No services section found in docker-compose.yml." - exit 1 - fi } export CYPRESS_WORKDIR="$(pwd)/source/vendor/oxid-solution-catalysts/telecash-module/tests/e2e"