generated from PenaSide/GolangTemplate
in-docker integration tests
This commit is contained in:
parent
d9a5739ddd
commit
5f0b22a21a
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,5 +1,5 @@
|
||||
# Dependency directories (remove the comment below to include it)
|
||||
# vendor/
|
||||
vendor/
|
||||
.idea/
|
||||
.vscode
|
||||
.env
|
||||
|
@ -2,7 +2,7 @@
|
||||
FROM golang:1.20.3-alpine AS build
|
||||
|
||||
# Update packages and clear cache
|
||||
RUN apk update && apk add --no-cache curl && rm -rf /var/cache/apk/*
|
||||
RUN apk add --no-cache curl
|
||||
# Set work directory
|
||||
WORKDIR /app
|
||||
# Create binary directory
|
||||
@ -14,7 +14,7 @@ ADD ./tools/migrate /bin/golang-migrate/
|
||||
# Add main files to app
|
||||
ADD . .
|
||||
# Download go depences
|
||||
RUN go mod download
|
||||
# RUN go mod download
|
||||
# Build app
|
||||
RUN GOOS=linux go build -o bin ./...
|
||||
|
||||
@ -24,9 +24,9 @@ RUN GOOS=linux go build -o bin ./...
|
||||
FROM alpine:3.18.3 AS test
|
||||
|
||||
# Install packages
|
||||
RUN apk --no-cache add ca-certificates && rm -rf /var/cache/apk/*
|
||||
RUN apk --no-cache add ca-certificates
|
||||
# Set GO111MODULE env
|
||||
ENV GO111MODULE=off
|
||||
# ENV GO111MODULE=off
|
||||
# Create home directory
|
||||
WORKDIR /app
|
||||
# Copy build file
|
||||
|
10
Makefile
10
Makefile
@ -25,18 +25,20 @@ test.unit: ## run unit tests
|
||||
go test ./...
|
||||
|
||||
test.integration: ## run integration tests
|
||||
go mod vendor
|
||||
@make test.integration.up
|
||||
@make test.integration.start
|
||||
@make test.integration.down
|
||||
|
||||
test.integration.up: ## build integration test environment
|
||||
docker-compose -f deployments/test/docker-compose.yaml up -d
|
||||
docker-compose -f deployments/test/environment.yaml up -d --remove-orphans
|
||||
|
||||
test.integration.down: ## shutting down integration environment
|
||||
docker-compose -f deployments/test/docker-compose.yaml down --volumes --rmi local
|
||||
docker-compose -f deployments/test/environment.yaml down --volumes
|
||||
|
||||
test.integration.start: ## run integration test
|
||||
go test ./tests/integration/...
|
||||
docker-compose -p integration -f deployments/test/integration.yaml up --exit-code-from app --remove-orphans
|
||||
docker-compose -p integration -f deployments/test/integration.yaml down
|
||||
|
||||
test.e2e.start: ## run integration test
|
||||
go test ./tests/e2e/...
|
||||
@ -48,4 +50,4 @@ dev.up: ## run dev environment
|
||||
docker-compose -f deployments/dev/docker-compose.yaml up -d
|
||||
|
||||
dev.down: ## shutting down dev environment
|
||||
docker-compose -f deployments/dev/docker-compose.yaml down --volumes --rmi local
|
||||
docker-compose -f deployments/dev/docker-compose.yaml down --volumes --rmi local
|
||||
|
18
deployments/test/integration.yaml
Normal file
18
deployments/test/integration.yaml
Normal file
@ -0,0 +1,18 @@
|
||||
version: "3"
|
||||
|
||||
services:
|
||||
app:
|
||||
container_name: app
|
||||
image: golang:1
|
||||
volumes:
|
||||
- ../..:/app:ro,z
|
||||
working_dir: /app
|
||||
command: go test ./tests/integration/...
|
||||
environment:
|
||||
- CUSTOMER_SERVICE=customer-service:8000
|
||||
networks:
|
||||
- test_test
|
||||
|
||||
networks:
|
||||
test_test:
|
||||
external: true
|
@ -3,6 +3,7 @@ package integration_test
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@ -11,6 +12,8 @@ import (
|
||||
"penahub.gitlab.yandexcloud.net/pena-services/customer/tests/helpers"
|
||||
)
|
||||
|
||||
var customerServiceBase string = os.Getenv("CUSTOMER_SERVICE")
|
||||
|
||||
func TestSetAccountVerificationStatusNO(t *testing.T) {
|
||||
jwtUtil := helpers.InitializeJWT()
|
||||
|
||||
@ -25,7 +28,7 @@ func TestSetAccountVerificationStatusNO(t *testing.T) {
|
||||
}
|
||||
|
||||
response, getAccountErr := client.Patch[models.Account, models.ResponseErrorHTTP](ctx, &client.RequestSettings{
|
||||
URL: "http://localhost:8082/account/807f1f77bcf81cd799439077",
|
||||
URL: "http://" + customerServiceBase + "/account/807f1f77bcf81cd799439077",
|
||||
Body: models.SetAccountStatus{Status: models.AccountStatusNo},
|
||||
Headers: map[string]string{"Authorization": fmt.Sprintf("Bearer %s", token)},
|
||||
})
|
||||
@ -56,7 +59,7 @@ func TestSetAccountVerificationStatusORG(t *testing.T) {
|
||||
}
|
||||
|
||||
response, getAccountErr := client.Patch[models.Account, models.ResponseErrorHTTP](ctx, &client.RequestSettings{
|
||||
URL: "http://localhost:8082/account/807f1f77bcf81cd799439077",
|
||||
URL: "http://" + customerServiceBase + "/account/807f1f77bcf81cd799439077",
|
||||
Body: models.SetAccountStatus{Status: models.AccountStatusOrg},
|
||||
Headers: map[string]string{"Authorization": fmt.Sprintf("Bearer %s", token)},
|
||||
})
|
||||
@ -87,7 +90,7 @@ func TestSetAccountVerificationStatusNKO(t *testing.T) {
|
||||
}
|
||||
|
||||
response, getAccountErr := client.Patch[models.Account, models.ResponseErrorHTTP](ctx, &client.RequestSettings{
|
||||
URL: "http://localhost:8082/account/807f1f77bcf81cd799439077",
|
||||
URL: "http://" + customerServiceBase + "/account/807f1f77bcf81cd799439077",
|
||||
Body: models.SetAccountStatus{Status: models.AccountStatusNko},
|
||||
Headers: map[string]string{"Authorization": fmt.Sprintf("Bearer %s", token)},
|
||||
})
|
||||
@ -118,7 +121,7 @@ func TestSetAccountVerificationStatusFailure(t *testing.T) {
|
||||
}
|
||||
|
||||
response, getAccountErr := client.Patch[models.Account, models.ResponseErrorHTTP](ctx, &client.RequestSettings{
|
||||
URL: "http://localhost:8082/account/807f1f77bcf81cd799439077",
|
||||
URL: "http://" + customerServiceBase + "/account/807f1f77bcf81cd799439077",
|
||||
Body: models.SetAccountStatus{Status: "radnom-status"},
|
||||
Headers: map[string]string{"Authorization": fmt.Sprintf("Bearer %s", token)},
|
||||
})
|
||||
|
@ -25,7 +25,7 @@ func TestUpdateAccountName(t *testing.T) {
|
||||
}
|
||||
|
||||
response, getAccountErr := client.Patch[models.Account, models.ResponseErrorHTTP](ctx, &client.RequestSettings{
|
||||
URL: "http://localhost:8082/account",
|
||||
URL: "http://" + customerServiceBase + "/account",
|
||||
Body: models.Name{
|
||||
FirstName: "Ivan",
|
||||
Secondname: "Ivanov",
|
||||
|
Loading…
Reference in New Issue
Block a user