Skip to content

Commit

Permalink
Merge pull request #4 from ekhvalov/feat/week04
Browse files Browse the repository at this point in the history
Feat/week04
  • Loading branch information
ekhvalov committed Nov 21, 2023
2 parents 4bbec67 + f93d9e6 commit a1d9543
Show file tree
Hide file tree
Showing 536 changed files with 122,572 additions and 2,351 deletions.
139 changes: 96 additions & 43 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ version: '3'
silent: true

vars:
CLIENT_V1_SRC: ./api/client.v1.swagger.yml
CLIENT_V1_DST: ./internal/server-client/v1/server.gen.go
CLIENT_V1_PKG: clientv1

DOCKER_COMPOSE_FILES: |-
docker-compose.yml
docker-compose.sentry.yml
Expand All @@ -29,6 +25,8 @@ vars:

TOOLS_DIR:
sh: echo "$(pwd)/tools/bin"
TOOLS_COVERAGE_DIR:
sh: echo "$(pwd)/tools/coverage"

env:
COMPOSE_PROJECT_NAME: bankchat
Expand All @@ -44,7 +42,7 @@ tasks:

deps:
cmds:
- "{{.DOCKER_COMPOSE_CMD}} up -d"
- "{{.DOCKER_COMPOSE_CMD}} up -d {{.CLI_ARGS}}"

deps:cmd:
cmds:
Expand Down Expand Up @@ -108,57 +106,25 @@ tasks:
cmds:
- "{{.TOOLS_DIR}}/golangci-lint run -v --fix --timeout=5m ./..."

tests:
cmds:
- echo "- Tests"
- go test -race ./... | grep -v '\[no test files\]'

tests:e2e:
dotenv: [ ".env.e2e" ]
cmds:
- echo "- End-to-end tests"
# NOTE: It's important to run tests serial (without `-p` flag) – for correct `clientsPool` sharing.
- "ginkgo --failFast --timeout=1m --tags e2e {{.CLI_ARGS}} ./tests/e2e"

tests:integration:
# Create file '.env' to provide environment variables listed below, and replace values with yours.
# TEST_LOG_LEVEL=info
# TEST_KEYCLOAK_BASE_PATH="http://localhost:3010"
# TEST_KEYCLOAK_REALM=Bank
# TEST_KEYCLOAK_CLIENT_ID=integration-testing
# TEST_KEYCLOAK_CLIENT_SECRET=ku3uEwc7nVGlzcidXfdAz1nBYJMfIjKt
# TEST_KEYCLOAK_TEST_USER=integration-testing
# TEST_KEYCLOAK_TEST_PASSWORD=password
dotenv: [ ".env" ]
cmds:
- echo "- Integration tests"
- go test -tags integration -count 1 -race ./... | grep -v '\[no test files\]'

build:
cmds:
- echo "- Build"
- go build ./cmd/chat-service

generate:
aliases: [ "gen" ]
cmds:
- 'PATH="{{.TOOLS_DIR}}:$PATH" go generate ./...'
- task: gen:types
- task: ent:gen
- task: gen:api
- task: gen:e2e

gen:e2e:
vars:
E2E_CLIENT_V1_DST: ./tests/e2e/api/client/v1/client.gen.go
E2E_CLIENT_V1_PKG: apiclientv1
cmds:
- echo "[E2E] Generate client API..."
- "{{.TOOLS_DIR}}/oapi-codegen --old-config-style -generate types,client,spec -package {{.E2E_CLIENT_V1_PKG}} {{.CLIENT_V1_SRC}} > {{.E2E_CLIENT_V1_DST}}"

gen:types:
vars:
TYPES: |-
ChatID
FailedJobID
JobID
MessageID
ProblemID
UserID
Expand All @@ -170,9 +136,42 @@ tasks:
- 'go run ./cmd/gen-types {{.TYPES_PKG}} {{.TYPES | splitLines | join "," }} {{.TYPES_DST}}'

gen:api:
vars:
API_V1_TYPES: |
client
manager
cmds:
- for: { var: API_V1_TYPES }
task: gen:api-v1
vars:
TYPE: "{{.ITEM}}"
- for: { var: API_V1_TYPES }
task: gen:api-v1-e2e
vars:
TYPE: "{{.ITEM}}"

gen:api-v1:
internal: true
vars:
SRC: "./api/{{.TYPE}}.v1.swagger.yml"
DIR: "./internal/server-{{.TYPE}}/v1"
DST: "{{.DIR}}/server.gen.go"
PKG: "{{.TYPE}}v1"
cmds:
- "{{.TOOLS_DIR}}/oapi-codegen -generate types,server,spec -package {{.CLIENT_V1_PKG}} {{.CLIENT_V1_SRC}} > {{.CLIENT_V1_DST}}"
- "mkdir -p {{.DIR}}"
- "{{.TOOLS_DIR}}/oapi-codegen -generate types,server,spec -package {{.PKG}} {{.SRC}} > {{.DST}}"

gen:api-v1-e2e:
internal: true
vars:
DIR: "./tests/e2e/api/{{.TYPE}}/v1"
DST: "{{.DIR}}/{{.TYPE}}.gen.go"
SRC: "./api/{{.TYPE}}.v1.swagger.yml"
PKG: "api{{.TYPE}}v1"
cmds:
- echo "[E2E] Generate {{.TYPE}} API..."
- "mkdir -p {{.DIR}}"
- "{{.TOOLS_DIR}}/oapi-codegen --old-config-style -generate types,client,spec -package {{.PKG}} {{.SRC}} > {{.DST}}"

ent:new:
cmds:
Expand All @@ -184,7 +183,60 @@ tasks:
- 'PATH="{{.TOOLS_DIR}}:$PATH" go generate {{.GO_MODULE}}/internal/store'
- task: tidy

dev-tools:install:
tests:
aliases: [ "tests:unit" ]
cmds:
- echo "- Tests"
- go test -race ./... | grep -v '\[no test files\]'

tests:e2e:
dir: ./deploy/local
env:
COMPOSE_PROJECT_NAME: bankchate2e
cmds:
- echo "- End-to-end tests"
- docker compose --file docker-compose.e2e.yml rm --force --stop --volumes
- docker compose --file docker-compose.e2e.yml up --renew-anon-volumes --remove-orphans --exit-code-from tester

tests:integration:
# Create file '.env' to provide environment variables listed below, and replace values with yours.
# TEST_LOG_LEVEL=info
# TEST_KEYCLOAK_BASE_PATH="http://localhost:3010"
# TEST_KEYCLOAK_REALM=Bank
# TEST_KEYCLOAK_CLIENT_ID=integration-testing
# TEST_KEYCLOAK_CLIENT_SECRET=ku3uEwc7nVGlzcidXfdAz1nBYJMfIjKt
# TEST_KEYCLOAK_TEST_USER=integration-testing
# TEST_KEYCLOAK_TEST_PASSWORD=password
dotenv: [ ".env" ]
cmds:
- echo "- Integration tests"
- go test -tags integration -count 1 -race ./... | grep -v '\[no test files\]'

tests:all:
cmds:
- task: tests
- task: tests:integration
- task: tests:e2e

tests:coverage:
dotenv: [ ".env" ]
cmds:
- mkdir -p ./tools/coverage/unit ./tools/coverage/integration ./tools/coverage/e2e
- rm -rf ./tools/coverage/e2e/*
- rm -rf ./tools/coverage/unit/*
- rm -rf ./tools/coverage/integration/*
- echo "- Unit tests"
- "go test -cover ./... -args -test.gocoverdir={{.TOOLS_COVERAGE_DIR}}/unit | grep -v '\\[no test files\\]'"
- echo "- Integration tests"
- "go test -cover -tags integration ./... -args -test.gocoverdir={{.TOOLS_COVERAGE_DIR}}/integration | grep -v '\\[no test files\\]'"
- task: tests:e2e
- go tool covdata textfmt -i=./tools/coverage/unit,./tools/coverage/integration,./tools/coverage/e2e -o coverage.out
- go tool covdata percent -i=./tools/coverage/unit,./tools/coverage/integration,./tools/coverage/e2e
- echo "- Average coverage, %"
- go tool covdata percent -i=./tools/coverage/unit,./tools/coverage/integration,./tools/coverage/e2e | grep -v '\[no statements\]' | awk '{print $3}' | sed 's/%//' | awk '{ total += $1; count++ } END { print total/count }'

tools:install:
aliases: [ "dev-tools:install" ]
vars:
DEV_TOOLS: |
github.com/daixiang0/gci@v0.11.2
Expand All @@ -202,7 +254,8 @@ tasks:
- task: golangci:install
- task: tidy

golangci:install:
tools:install-golangci:
aliases: [ "golangci:install" ]
dir: "{{.TOOLS_DIR}}"
cmds:
- wget -q "{{.GOLANGCI_LINT_URL}}/{{.GOLANGCI_LINT_ARCHIVE_FILE}}"
Expand Down
2 changes: 2 additions & 0 deletions api/client.v1.swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ info:
servers:
- url: http://localhost:8080/v1
description: Development server
- url: /v1
description: E2E server

paths:
/sendMessage:
Expand Down
109 changes: 109 additions & 0 deletions api/manager.v1.swagger.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
openapi: 3.0.3
info:
title: Bank Support Chat Manager API
version: v1

servers:
- url: http://localhost:8081/v1
description: Development server
- url: /v1
description: Development e2e server

paths:
/getFreeHandsBtnAvailability:
post:
description: Get availability to handle new problems.
parameters:
- $ref: '#/components/parameters/XRequestIDHeader'
requestBody:
required: false
responses:
'200':
description: Availability result
content:
application/json:
schema:
$ref: '#/components/schemas/GetFreeHandsBtnAvailabilityResponse'

/freeHands:
post:
description: Declare readiness to handle problems.
parameters:
- $ref: '#/components/parameters/XRequestIDHeader'
requestBody:
required: false
responses:
'200':
description: Declaration sent
content:
application/json:
schema:
$ref: '#/components/schemas/FreeHandsResponse'

security:
- bearerAuth: [ ]

components:
securitySchemes:
bearerAuth:
type: http
scheme: bearer
bearerFormat: JWT

parameters:
XRequestIDHeader:
in: header
name: X-Request-ID
schema:
type: string
format: uuid
x-go-type: types.RequestID
x-go-type-import:
path: "github.com/ekhvalov/bank-chat-service/internal/types"
required: true

schemas:
# Common.

Error:
required: [ message, code ]
properties:
code:
$ref: "#/components/schemas/ErrorCode"
message:
type: string
details:
type: string

ErrorCode:
type: integer
description: contains HTTP error codes and specific business logic error codes (the last must be >= 1000).
minimum: 400
enum:
- 5000
x-enum-varnames:
- ErrorCodeManagerOverloadedError

# /getFreeHandsBtnAvailability

GetFreeHandsBtnAvailabilityResponse:
properties:
data:
$ref: '#/components/schemas/FreeHandsAvailability'
error:
$ref: "#/components/schemas/Error"

FreeHandsAvailability:
required: [ available ]
properties:
available:
type: boolean

# /freeHands

FreeHandsResponse:
properties:
data:
type: null
error:
$ref: '#/components/schemas/Error'
Loading

0 comments on commit a1d9543

Please sign in to comment.