Skip to content

Commit

Permalink
Included option to run integration tests locally (guacsec#1361)
Browse files Browse the repository at this point in the history
* Included option to integration tests locally

- Included an option to run integration tests locally.

Signed-off-by: naveensrinivasan <[email protected]>

* Improve integration test setup

Signed-off-by: naveensrinivasan <[email protected]>

* Code review comments.

Signed-off-by: naveensrinivasan <[email protected]>

---------

Signed-off-by: naveensrinivasan <[email protected]>
  • Loading branch information
naveensrinivasan authored Oct 30, 2023
1 parent a20dbc7 commit 2af1cc4
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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=<your 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 ./...
Expand Down Expand Up @@ -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 \
Expand Down
59 changes: 59 additions & 0 deletions integration.docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 2af1cc4

Please sign in to comment.