From 2af1cc4643b44f27dbfafe12b15c2da85c4ed5e3 Mon Sep 17 00:00:00 2001 From: Naveen <172697+naveensrinivasan@users.noreply.github.com> Date: Mon, 30 Oct 2023 10:17:19 -0500 Subject: [PATCH] Included option to run integration tests locally (#1361) * Included option to integration tests locally - Included an option to run integration tests locally. Signed-off-by: naveensrinivasan <172697+naveensrinivasan@users.noreply.github.com> * Improve integration test setup Signed-off-by: naveensrinivasan <172697+naveensrinivasan@users.noreply.github.com> * Code review comments. Signed-off-by: naveensrinivasan <172697+naveensrinivasan@users.noreply.github.com> --------- Signed-off-by: naveensrinivasan <172697+naveensrinivasan@users.noreply.github.com> --- Makefile | 21 ++++++++++++ integration.docker-compose.yaml | 59 +++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 integration.docker-compose.yaml diff --git a/Makefile b/Makefile index ef18b7c38e..88f160b886 100644 --- a/Makefile +++ b/Makefile @@ -20,10 +20,26 @@ test: generate echo 'mode: atomic' > coverage.txt && go test -covermode=atomic -coverprofile=coverage.txt -v -race -timeout=30s ./... # Run the integration tests. Requires github token for scorecard (GITHUB_AUTH_TOKEN=) +# To run it locally you can run the following command: make start-integration-service .PHONY: integration-test integration-test: generate check-env go test -tags=integration ./... +# Runs the integration tests locally using docker-compose to start the dependencies and cleans up after itself. +.PHONY: integration-test-local +integration-test-local: generate check-env start-integration-service + # wait for the service to start which is a http server at 8080 port + @echo "Waiting for the service to start" + @counter=0; \ + while [ $$counter -lt 15 ] && ! curl --silent --head --output /dev/null --fail http://localhost:8080; do \ + printf '.'; \ + sleep 1; \ + counter=$$((counter+1)); \ + done; \ + [ $$counter -eq 15 ] && { echo "Service did not start in time"; exit 1; } || echo "Service is up!" + ENT_TEST_DATABASE_URL='postgresql://guac:guac@localhost/guac?sslmode=disable' go test -tags=integration ./... + $(CONTAINER) compose down + .PHONY: integration-merge-test integration-merge-test: generate check-env go test -tags=integrationMerge ./... @@ -137,6 +153,11 @@ start-service: check-docker-compose-tool-check stop-service: $(CONTAINER) compose down +# This is a helper target to run the integration tests locally. +.PHONY: start-integration-service +start-integration-service: check-docker-compose-tool-check + $(CONTAINER) compose -f integration.docker-compose.yaml up --force-recreate -d + .PHONY: check-docker-tool-check check-docker-tool-check: @if ! command -v $(CONTAINER) >/dev/null 2>&1; then \ diff --git a/integration.docker-compose.yaml b/integration.docker-compose.yaml new file mode 100644 index 0000000000..d89e12a017 --- /dev/null +++ b/integration.docker-compose.yaml @@ -0,0 +1,59 @@ +version: "3.8" + +volumes: + arangodb_data_container: + arangodb_apps_data_container: + prometheus_data: + grafana_data: + +services: + + postgres: + image: postgres:15 + environment: + POSTGRES_USER: guac + POSTGRES_PASSWORD: guac + POSTGRES_HOST_AUTH_METHOD: trust + networks: [frontend] + ports: + - "5432:5432" + volumes: + - ./container_files/pg:/var/lib/postgresql/data + + guac-graphql: + image: "local-organic-guac" + command: "/opt/guac/guacgql --gql-debug --gql-backend arango" + working_dir: /guac + restart: on-failure + depends_on: + arangodb: + condition: service_healthy + ports: + - "$GUAC_API_PORT:8080" + volumes: + - ./container_files/guac:/guac + healthcheck: + test: ["CMD", "wget", "--spider", "http://localhost:8080"] + interval: 10s + timeout: 10s + retries: 3 + start_period: 5s + + arangodb: + image: arangodb:latest + environment: + ARANGO_ROOT_PASSWORD: test123 + ports: + - 8529:8529 + volumes: + - arangodb_data_container:/var/lib/arangodb3 + - arangodb_apps_data_container:/var/lib/arangodb3-apps + healthcheck: + test: ["CMD", "wget", "--spider", "http://localhost:8529"] + interval: 10s + timeout: 10s + retries: 3 + start_period: 1s +networks: + frontend: + driver: bridge