diff --git a/.github/workflows/test-integration.yml b/.github/workflows/test-integration.yml new file mode 100644 index 0000000..3a24e1f --- /dev/null +++ b/.github/workflows/test-integration.yml @@ -0,0 +1,10 @@ +name: Test Integration +on: push + +jobs: + test-integration-api: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v3 + - name: Test Integration + run: make test-integration-api diff --git a/.github/workflows/test-unit.yml b/.github/workflows/test-unit.yml new file mode 100644 index 0000000..e117bb7 --- /dev/null +++ b/.github/workflows/test-unit.yml @@ -0,0 +1,16 @@ +name: Test Unit +on: push + +jobs: + test: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v3 + - name: Test Unit + run: make test-unit +# test-integration-api: +# runs-on: ubuntu-22.04 +# steps: +# - uses: actions/checkout@v3 +# - name: Test Unit +# run: make test-integration-api diff --git a/Makefile b/Makefile index 02c913b..fe4c788 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,9 @@ DOCKER_COMPOSE_FILENAME=deployments/docker-compose/docker-compose.yaml start: vendor-install - docker-compose -f ${DOCKER_COMPOSE_FILENAME} down -v --remove-orphans ; docker-compose -f ${DOCKER_COMPOSE_FILENAME} up -d -start-from-scratch: vendor-install - docker-compose -f ${DOCKER_COMPOSE_FILENAME} down -v --remove-orphans ; docker-compose -f ${DOCKER_COMPOSE_FILENAME} up --build -d + docker-compose -f ${DOCKER_COMPOSE_FILENAME} up -d +start-from-scratch: stop + docker-compose --file ${DOCKER_COMPOSE_FILENAME} --profile httpapi up --remove-orphans --renew-anon-volumes --force-recreate --build -d stop: docker-compose -f ${DOCKER_COMPOSE_FILENAME} down restart: stop start @@ -11,11 +11,16 @@ logs-api: docker-compose -f ${DOCKER_COMPOSE_FILENAME} logs -f api logs-verifier: docker-compose -f ${DOCKER_COMPOSE_FILENAME} logs -f verifier -test: - docker run -v $(shell pwd):/app golang:1.20.0 /bin/bash -c 'cd /app && GO111MODULE=on go test -mod vendor -covermode=count -coverprofile=assets/coverage/coverage.out -v ./... && go tool cover -html=assets/coverage/coverage.out -o=assets/coverage/coverage.html' -test-integration-api: +test-unit: vendor-install + docker run -v $(shell pwd):/app -w /app golang:1.20.0 /bin/bash \ + -c 'go test -covermode=count -coverprofile=assets/coverage/coverage.out -v ./internal/... && go tool cover -html=assets/coverage/coverage.out -o=assets/coverage/coverage.html' +test-integration-api: start docker-compose -f ${DOCKER_COMPOSE_FILENAME} run test-integration-api +lint-golangci: vendor-install + docker run --rm -v $(shell pwd):/app -w /app golangci/golangci-lint:v1.50.1 \ + golangci-lint run --timeout 5m30s -v lint-architecture: - docker run --rm -v $(shell pwd):/app -w /app golang:1.20.0 /bin/bash -c "go install github.com/fdaines/arch-go@v1.4.2 && arch-go -v" + docker run --rm -v $(shell pwd):/app -w /app golang:1.20.0 /bin/bash \ + -c "go install github.com/fdaines/arch-go@v1.4.2 && arch-go -v" vendor-install: @if [ -d "vendor" ]; then echo "Vendor folder already exists. Skip vendor installing."; else docker run --rm -v $(shell pwd):/app -w /app golang:1.20.0 /bin/bash -c "go mod tidy && go mod vendor"; fi \ No newline at end of file diff --git a/README.md b/README.md index b14c559..7667d3a 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +[![Test Unit][test-unit-badge]][test-unit-url] + # Space Trouble ## Requirements @@ -117,3 +119,6 @@ Technical requirements: * Please, use github or bitbucket. * Commit your changes often. Do not push the whole project in one commit. + +[test-unit-badge]: https://github.com/mgerasimchuk/space-trouble/actions/workflows/test-unit.yml/badge.svg +[test-unit-url]: https://github.com/mgerasimchuk/space-trouble/actions/workflows/test-unit.yml \ No newline at end of file diff --git a/deployments/docker-compose/.env b/deployments/docker-compose/.env index 338da7b..8530cda 100644 --- a/deployments/docker-compose/.env +++ b/deployments/docker-compose/.env @@ -8,7 +8,6 @@ # 6 - TraceLevel LOG_LEVEL: 4 - DB_HOST: db DB_PORT: 5432 DB_NAME: postgres @@ -19,7 +18,6 @@ LAUNCHPAD_API_BASE_URI: "https://api.spacexdata.com" LANDPAD_API_BASE_URI: "https://api.spacexdata.com" -HTTPSERVER: HTTP_SERVER_PORT: 8080 # see: vendor/github.com/gin-gonic/gin/mode.go # debug diff --git a/deployments/docker-compose/docker-compose.yaml b/deployments/docker-compose/docker-compose.yaml index 9b63d48..79d2c03 100644 --- a/deployments/docker-compose/docker-compose.yaml +++ b/deployments/docker-compose/docker-compose.yaml @@ -4,10 +4,11 @@ services: api: image: golang:1.20.0 restart: "no" - env_file: - - ./../../deployments/docker-compose/.env depends_on: - "db" + env_file: + - ./../../deployments/docker-compose/.env + working_dir: /app volumes: - ./../../:/app ports: @@ -16,10 +17,11 @@ services: verifier: image: golang:1.20.0 restart: "no" - env_file: - - ./../../deployments/docker-compose/.env depends_on: - "db" + env_file: + - ./../../deployments/docker-compose/.env + working_dir: /app volumes: - ./../../:/app entrypoint: bash -c 'while !