-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
134 lines (110 loc) · 3.82 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
generate-code:
# Install mockgen
go install github.com/golang/mock/[email protected]
# Generate mocks for test purposes
# Generate mock redirection repository
mockgen -destination=./test/mock/redirection_repository.go \
-package=mock \
-mock_names=Repository=MockRedirectionRepository \
github.com/emanuelefalzone/bitly/internal/application/redirection Repository
# Generate mock event repository
mockgen -destination=./test/mock/event_repository.go \
-package=mock \
-mock_names=Repository=MockEventRepository \
github.com/emanuelefalzone/bitly/internal/application/event Repository
# Generate mock key generator
mockgen -destination=./test/mock/key_generator_service.go \
-package=mock \
github.com/emanuelefalzone/bitly/internal/application/service KeyGenerator
# Install protobuf and grpc
go get google.golang.org/grpc/cmd/[email protected]
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc
go install google.golang.org/protobuf/cmd/protoc-gen-go
# Generate protobuf and grpc server
protoc \
--go_out=. \
--go_opt=paths=source_relative \
--go-grpc_out=. \
--go-grpc_opt=paths=source_relative \
internal/port/grpc/pb/bitly_service.proto
generate-docs:
# Ensure docs directory exists
mkdir -p ./docs
# Install proto documentation generator
go get github.com/pseudomuto/protoc-gen-doc/cmd/[email protected]
go install github.com/pseudomuto/protoc-gen-doc/cmd/protoc-gen-doc
# Generate documentation for grpc service
protoc \
--doc_out=./docs \
--doc_opt=html,proto.html \
internal/port/grpc/pb/bitly_service.proto
# Install swag
go get github.com/swaggo/swag/[email protected]
go get github.com/swaggo/swag/cmd/[email protected]
go install github.com/swaggo/swag/cmd/swag
# Generate documentation for grpc service
swag init -d internal/port/http --generalInfo server.go
build-for-production:
# Build removing debug info
go build -ldflags "-s -w" -v ./cmd/main.go
build-for-development:
# Build using -race to check for race conditions while running
go build -race -v ./cmd/main.go
CVPKG=$(go list ./internal/... | grep -v pb | tr '\n' ',')
run-unit-tests:
# Run unit tests with coverage
go test ./internal/... -v \
-count=1 \
-coverpkg=$(CVPKG) \
-coverprofile unit-coverage.out \
--tags=unit
# Generate human readable coverage result
go tool cover -html unit-coverage.out -o unit-coverage.html
run-acceptance-tests:
# Run acceptance tests with coverage
go test ./internal/application/application_test.go -v \
-count=1 \
-coverpkg=$(CVPKG) \
-coverprofile acceptance-coverage.out \
--tags=acceptance
# Generate human readable coverage result
go tool cover -html acceptance-coverage.out -o acceptance-coverage.html
setup-docker-environment:
docker-compose up --detach --build
teardown-docker-environment:
docker-compose down
run-integration-tests:
# Run integration tests with coverage
INTEGRATION_REDIS_CONNECTION_STRING=redis://localhost:6379 \
go test \
./internal/application/redirection/redis_repository_test.go \
-v \
-count=1 \
-coverpkg=$(CVPKG) \
-coverprofile integration-coverage-redis.out \
--tags=integration
INTEGRATION_MONGO_CONNECTION_STRING=mongodb://root:example@localhost:27017 \
go test \
./internal/application/event/mongo_repository_test.go \
-v \
-count=1 \
-coverpkg=$(CVPKG) \
-coverprofile integration-coverage-mongo.out \
--tags=integration
# Generate human readable coverage result
go tool cover -html integration-coverage-redis.out -o integration-coverage-redis.html
go tool cover -html integration-coverage-mongo.out -o integration-coverage-mongo.html
run-e2e-tests:
# Run e2e tests
E2E_GRPC_SERVER=localhost:6060 \
go test \
./internal/port/grpc/server_test.go \
-v \
-count=1 \
--tags=e2e
E2E_HTTP_SERVER=http://localhost:7070 \
go test \
./internal/port/http/server_test.go \
-v \
-count=1 \
--tags=e2e