-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
63 lines (47 loc) · 1.95 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include .env
#export
.PHONY:
.SILENT:
.DEFAULT_GOAL := docker-compose
# https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
test: ## Run unit tests
go test --short -v -count=1 -timeout=30s -coverprofile=coverage.out ./...
test-integration: ## Run all integration tests
docker run --rm -d --name=test_db -e POSTGRES_DB=test -e POSTGRES_USER=username -e POSTGRES_PASSWORD=qwerty123 -p 6001:5432 postgres:15
sleep 2s
migrate -path ./migrations -database "postgres://username:[email protected]:6001/test?sslmode=disable" up 1
go test -v -count=1 ./integration-tests/
docker stop test_db
cover: ## Run unit tests and open the coverage report
go test --short -v -count=1 -timeout=30s -coverprofile=coverage.out ./...
go tool cover -html=./coverage.out -o coverage.html
open coverage.html
docker-compose:
docker compose up --build --force-recreate
swagger: ## Generate api documentation
$$(go env GOPATH)/bin/swag init
$$(go env GOPATH)/bin/swag fmt
gomock: ## Generate service mocks
# export PATH=$PATH:$(go env GOPATH)/bin
go generate internal/service/service.go
install:
go install github.com/swaggo/swag/cmd/swag@latest
go install github.com/golang/mock/[email protected]
# go install golang.org/x/tools/gopls@latest
curl -L https://github.com/golang-migrate/migrate/releases/download/v4.14.1/migrate.linux-amd64.tar.gz | tar xvz
mv migrate.linux-amd64 /usr/bin/migrate
# migrate_params = -path ./migrations -database "postgres://<username>:<password>@ip-addr:port/postgres?sslmode=disable"
migrate-up:
migrate $(migrate_params) up $(n)
migrate-down:
migrate $(migrate_params) down $(n)
migrate-version:
migrate $(migrate_params) version
migrate-goto:
migrate $(migrate_params) goto $(v)
migrate-drop:
migrate $(migrate_params) drop
migrate-create:
migrate create -ext sql -dir ./migrations/ -seq $(NAME)