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)
|
# Dependency directories (remove the comment below to include it)
|
||||||
# vendor/
|
vendor/
|
||||||
.idea/
|
.idea/
|
||||||
.vscode
|
.vscode
|
||||||
.env
|
.env
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
FROM golang:1.20.3-alpine AS build
|
FROM golang:1.20.3-alpine AS build
|
||||||
|
|
||||||
# Update packages and clear cache
|
# 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
|
# Set work directory
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
# Create binary directory
|
# Create binary directory
|
||||||
@ -14,7 +14,7 @@ ADD ./tools/migrate /bin/golang-migrate/
|
|||||||
# Add main files to app
|
# Add main files to app
|
||||||
ADD . .
|
ADD . .
|
||||||
# Download go depences
|
# Download go depences
|
||||||
RUN go mod download
|
# RUN go mod download
|
||||||
# Build app
|
# Build app
|
||||||
RUN GOOS=linux go build -o bin ./...
|
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
|
FROM alpine:3.18.3 AS test
|
||||||
|
|
||||||
# Install packages
|
# Install packages
|
||||||
RUN apk --no-cache add ca-certificates && rm -rf /var/cache/apk/*
|
RUN apk --no-cache add ca-certificates
|
||||||
# Set GO111MODULE env
|
# Set GO111MODULE env
|
||||||
ENV GO111MODULE=off
|
# ENV GO111MODULE=off
|
||||||
# Create home directory
|
# Create home directory
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
# Copy build file
|
# Copy build file
|
||||||
|
|||||||
10
Makefile
10
Makefile
@ -25,18 +25,20 @@ test.unit: ## run unit tests
|
|||||||
go test ./...
|
go test ./...
|
||||||
|
|
||||||
test.integration: ## run integration tests
|
test.integration: ## run integration tests
|
||||||
|
go mod vendor
|
||||||
@make test.integration.up
|
@make test.integration.up
|
||||||
@make test.integration.start
|
@make test.integration.start
|
||||||
@make test.integration.down
|
@make test.integration.down
|
||||||
|
|
||||||
test.integration.up: ## build integration test environment
|
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
|
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
|
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
|
test.e2e.start: ## run integration test
|
||||||
go test ./tests/e2e/...
|
go test ./tests/e2e/...
|
||||||
@ -48,4 +50,4 @@ dev.up: ## run dev environment
|
|||||||
docker-compose -f deployments/dev/docker-compose.yaml up -d
|
docker-compose -f deployments/dev/docker-compose.yaml up -d
|
||||||
|
|
||||||
dev.down: ## shutting down dev environment
|
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 (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
@ -11,6 +12,8 @@ import (
|
|||||||
"penahub.gitlab.yandexcloud.net/pena-services/customer/tests/helpers"
|
"penahub.gitlab.yandexcloud.net/pena-services/customer/tests/helpers"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var customerServiceBase string = os.Getenv("CUSTOMER_SERVICE")
|
||||||
|
|
||||||
func TestSetAccountVerificationStatusNO(t *testing.T) {
|
func TestSetAccountVerificationStatusNO(t *testing.T) {
|
||||||
jwtUtil := helpers.InitializeJWT()
|
jwtUtil := helpers.InitializeJWT()
|
||||||
|
|
||||||
@ -25,7 +28,7 @@ func TestSetAccountVerificationStatusNO(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
response, getAccountErr := client.Patch[models.Account, models.ResponseErrorHTTP](ctx, &client.RequestSettings{
|
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},
|
Body: models.SetAccountStatus{Status: models.AccountStatusNo},
|
||||||
Headers: map[string]string{"Authorization": fmt.Sprintf("Bearer %s", token)},
|
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{
|
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},
|
Body: models.SetAccountStatus{Status: models.AccountStatusOrg},
|
||||||
Headers: map[string]string{"Authorization": fmt.Sprintf("Bearer %s", token)},
|
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{
|
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},
|
Body: models.SetAccountStatus{Status: models.AccountStatusNko},
|
||||||
Headers: map[string]string{"Authorization": fmt.Sprintf("Bearer %s", token)},
|
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{
|
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"},
|
Body: models.SetAccountStatus{Status: "radnom-status"},
|
||||||
Headers: map[string]string{"Authorization": fmt.Sprintf("Bearer %s", token)},
|
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{
|
response, getAccountErr := client.Patch[models.Account, models.ResponseErrorHTTP](ctx, &client.RequestSettings{
|
||||||
URL: "http://localhost:8082/account",
|
URL: "http://" + customerServiceBase + "/account",
|
||||||
Body: models.Name{
|
Body: models.Name{
|
||||||
FirstName: "Ivan",
|
FirstName: "Ivan",
|
||||||
Secondname: "Ivanov",
|
Secondname: "Ivanov",
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user