-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hw15: Тестирование микросервисов #24
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,9 @@ clean: | |
test: | ||
go test -race ./... | ||
|
||
integration-test: | ||
go test -tags integration ./... | ||
|
||
lint: | ||
go get github.com/golangci/golangci-lint/cmd/golangci-lint | ||
golangci-lint run --build-tags server,sender,scheduler --disable exhaustivestruct ./... | ||
|
@@ -25,4 +28,13 @@ migrate: | |
generate: | ||
go generate ./... | ||
|
||
up: | ||
docker-compose -f docker/docker-compose.yaml up --scale bdd-tests=0 | ||
|
||
down: | ||
docker-compose -f docker/docker-compose.yaml down | ||
|
||
bdd: | ||
docker-compose -f docker/docker-compose.yaml run --rm bdd-tests | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. при ошибке получаем работающий compose например, у меня был занят 8080 порт, тесты оставили после себя мусорные запущенные контейнеры
кстати, чтобы такого не происходило, в There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Сделал бинд на localhost. |
||
|
||
.PHONY: build |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
FROM golang:latest as builder | ||
|
||
WORKDIR /app | ||
COPY . . | ||
|
||
ENV CGO_ENABLED=0 | ||
ENV GOOS=linux | ||
|
||
RUN go get -d -v | ||
RUN go get -u github.com/pressly/goose/cmd/goose | ||
|
||
RUN go build -tags=server,sender,scheduler -ldflags="-w -s" -o calendar . | ||
|
||
|
||
# New stage | ||
FROM alpine:latest | ||
WORKDIR /app | ||
|
||
COPY --from=builder /app/calendar . | ||
COPY --from=builder /go/bin/goose . | ||
|
||
COPY migrations /app/migrations/ | ||
COPY docker/configs /app/configs/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
FROM golang:latest | ||
|
||
COPY . /app/ | ||
WORKDIR /app | ||
|
||
ENV CGO_ENABLED=0 | ||
ENV GOOS=linux | ||
|
||
VOLUME /app/godogs | ||
RUN go get -u github.com/cucumber/godog/cmd/godog | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. если есть vendor, то можно из него собирать, чтобы быстрее было There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Для godog не нашел чего-то свежего и звездного в docker hub :( |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
--- | ||
logger: | ||
output: | ||
- stdout | ||
error: | ||
- stderr | ||
level: info | ||
encoding: json | ||
db: | ||
path: user=postgres password=postgres dbname=postgres host=postgres-golang-learning port=5432 sslmode=disable | ||
type: sql | ||
server: | ||
host: 0.0.0.0 | ||
httpPort: 8080 | ||
grpcPort: 9090 | ||
broker: | ||
amqp: amqp://guest:guest@rabbitmq-golang-learning:5672/ | ||
exchange: events | ||
exchangeType: direct | ||
routingKey: notifications | ||
scheduler: | ||
checkInterval: 3 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
version: "3.5" | ||
|
||
networks: | ||
server: | ||
driver: bridge | ||
rabbit: | ||
driver: bridge | ||
postgres: | ||
driver: bridge | ||
|
||
services: | ||
postgres-golang-learning: | ||
image: postgres:alpine | ||
ports: | ||
- "5432:5432" | ||
expose: | ||
- 5432 | ||
environment: | ||
POSTGRES_USER: postgres | ||
POSTGRES_PASSWORD: postgres | ||
networks: | ||
- postgres | ||
|
||
rabbitmq-golang-learning: | ||
image: rabbitmq:3-management | ||
ports: | ||
- "15672:15672" | ||
- "5672:5672" | ||
expose: | ||
- 5672 | ||
- 15672 | ||
networks: | ||
- rabbit | ||
|
||
calendar-base-image: | ||
image: calendar-base-image | ||
build: | ||
context: .. | ||
dockerfile: docker/Dockerfile | ||
command: "true" | ||
|
||
server: | ||
image: calendar-base-image | ||
container_name: calendar-server | ||
ports: | ||
- "8080:8080" | ||
- "9090:9090" | ||
expose: | ||
- 8080 | ||
- 9090 | ||
depends_on: | ||
- calendar-base-image | ||
- postgres-golang-learning | ||
networks: | ||
- server | ||
- postgres | ||
command: > | ||
/bin/sh -c ' | ||
while ! nc -z postgres-golang-learning 5432; | ||
do | ||
echo "waiting for postgres-golang-learning"; | ||
sleep 1; | ||
done; | ||
|
||
/app/goose -dir migrations postgres "user=postgres password=postgres dbname=postgres host=postgres-golang-learning port=5432 sslmode=disable" up; | ||
/app/calendar server; | ||
' | ||
|
||
sender: | ||
image: calendar-base-image | ||
container_name: calendar-sender | ||
depends_on: | ||
- calendar-base-image | ||
- rabbitmq-golang-learning | ||
networks: | ||
- rabbit | ||
command: > | ||
/bin/sh -c ' | ||
while ! nc -z rabbitmq-golang-learning 5672; | ||
do | ||
echo "waiting for rabbitmq-golang-learning"; | ||
sleep 1; | ||
done; | ||
|
||
/app/calendar sender; | ||
' | ||
|
||
scheduler: | ||
image: calendar-base-image | ||
container_name: calendar-scheduler | ||
depends_on: | ||
- postgres-golang-learning | ||
- rabbitmq-golang-learning | ||
- sender | ||
networks: | ||
- postgres | ||
- rabbit | ||
command: > | ||
/bin/sh -c ' | ||
while ! nc -z postgres-golang-learning 5432; | ||
do | ||
echo "waiting for postgres-golang-learning"; | ||
sleep 1; | ||
done; | ||
|
||
while ! nc -z rabbitmq-golang-learning 5672; | ||
do | ||
echo "waiting for rabbitmq-golang-learning"; | ||
sleep 1; | ||
done; | ||
|
||
/app/goose -dir migrations postgres "user=postgres password=postgres dbname=postgres host=postgres-golang-learning port=5432 sslmode=disable" up; | ||
/app/calendar scheduler; | ||
' | ||
|
||
bdd-tests: | ||
build: | ||
context: .. | ||
dockerfile: docker/Dockerfile-bdd-tests | ||
image: calendar-bdd-tests | ||
environment: | ||
- REST_SERVER=http://server:8080 | ||
volumes: | ||
- ../godogs:/app/godogs | ||
working_dir: /app/godogs | ||
depends_on: | ||
- server | ||
- scheduler | ||
- sender | ||
networks: | ||
- server | ||
command: godog -f progress |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
Feature: check deliver messages | ||
|
||
Scenario: Check upcoming event | ||
Given delete events for user id 49 | ||
And create event with user id 49, title "test-upcoming-event", starts in 7 days | ||
When get events by user id 49 after 5 seconds | ||
And check event notification state | ||
Then received true status | ||
|
||
Scenario: Check event that comes more than 2 week | ||
Given delete events for user id 53 | ||
And create event with user id 53, title "test-non-upcoming-event", starts in 21 days | ||
When get events by user id 53 after 5 seconds | ||
And check event notification state | ||
Then received false status |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
не прошли + оставили после себя мусор
логов явно не хватает
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Речь именно про сохранение вывода в файл?
Progress output, на первый взгляд, весьма удобная и читаемая штука.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Тесты также поправил (на самом деле нужны были healthcheck).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
я имел в виду стектрейс до места, где именно упали тесты