-
Notifications
You must be signed in to change notification settings - Fork 9
/
Makefile
182 lines (151 loc) · 6.79 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# Copyright (c) 2018 TFG Co <[email protected]>
# Author: TFG Co <[email protected]>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
# the Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
MOCKGENERATE := go run go.uber.org/mock/[email protected]
GINKGO := go run github.com/onsi/ginkgo/[email protected]
build:
@mkdir -p bin
@go build -o bin/pusher main.go
setup-ci:
@go get github.com/mattn/goveralls
@go get github.com/onsi/ginkgo/ginkgo
deps:
@echo "Starting dependencies..."
@docker compose --project-name pusher up --wait --renew-anon-volumes
@echo "Dependencies started successfully."
stop-deps:
@docker compose --project-name pusher down --remove-orphans --volumes
rtfd:
@rm -rf docs/_build
@sphinx-build -b html -d ./docs/_build/doctrees ./docs/ docs/_build/html
@open docs/_build/html/index.html
run:
@go run main.go
gcm:
@go run main.go gcm
apns:
@go run main.go apns --certificate=./tls/_fixtures/certificate-valid.pem
local-deps:
@docker compose --project-name pusher up --wait --renew-anon-volumes
setup:
# Ensuring librdkafka is installed in Mac OS
@/bin/bash -c '[ "`uname -s`" == "Darwin" ] && [ "`which brew`" != "" ] && [ ! -d "/usr/local/Cellar/librdkafka" ] && echo "librdkafka was not found. Installing with brew..." && brew install librdkafka; exit 0'
# Ensuring librdkafka is installed in Debian and Ubuntu
@/bin/bash -c '[ "`uname -s`" == "Linux" ] && [ "`which apt-get`" != "" ] && echo "Ensuring librdkafka is installed..." && ./debian-install-librdkafka.sh; exit 0'
@go get -u github.com/onsi/ginkgo/ginkgo
@go get github.com/gordonklaus/ineffassign
test: test-unit test-integration
test-coverage-func:
@mkdir -p _build
@-rm -rf _build/test-coverage-all.out
@echo "mode: count" > _build/test-coverage-all.out
@bash -c 'for f in $$(find . -name "*.coverprofile"); do tail -n +2 $$f >> _build/test-coverage-all.out; done'
@echo
@echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-"
@echo "Functions NOT COVERED by Tests"
@echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-"
@go tool cover -func=_build/test-coverage-all.out | egrep -v "100.0[%]"
test-coverage: test test-coverage-run
test-coverage-run:
@mkdir -p _build
@-rm -rf _build/test-coverage-all.out
@echo "mode: count" > _build/test-coverage-all.out
@bash -c 'for f in $$(find . -name "*.coverprofile"); do tail -n +2 $$f >> _build/test-coverage-all.out; done'
test-coverage-html cover:
@go tool cover -html=_build/test-coverage-all.out
test-coverage-write-html:
@go tool cover -html=_build/test-coverage-all.out -o _build/test-coverage.html
test-services: stop-deps deps test-db-drop test-db-create
@echo "Required test services are up."
test-db-drop:
@psql -U postgres -h localhost -p 8585 -f db/drop-test.sql > /dev/null
test-db-create:
@psql -U postgres -h localhost -p 8585 -f db/create-test.sql > /dev/null
test-unit:
@echo
@echo "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="
@echo "= Running unit tests... ="
@echo "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="
@echo
@export $ACK_GINKGO_RC=true
@$(GINKGO) -trace -r --randomizeAllSpecs --randomizeSuites --cover --focus="\[Unit\].*" --skipPackage=e2e .
@#$(MAKE) test-coverage-func
@echo
@echo "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="
@echo "= Unit tests finished. ="
@echo "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="
@echo
run-integration-test:
@echo
@echo "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="
@echo "= Running integration tests... ="
@echo "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="
@echo
@export $ACK_GINKGO_RC=true
@$(GINKGO) -trace -r -tags=integration --randomizeAllSpecs --randomizeSuites --focus="\[Integration\].*" .
@echo
@echo "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="
@echo "= Integration tests finished. ="
@echo "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="
@echo
test-integration: deps test-db-drop test-db-create run-integration-test
lint:
@golangci-lint run
build-image-dev:
@docker build -f Dockerfile.local -t pusher:local .
lint-container-dev: build-image-dev
@docker run \
--rm \
--name pusher-lint \
--volume "${PWD}":/go/src/github.com/topfreegames/pusher \
pusher:local golangci-lint run
build-container-dev: build-image-dev
@docker run \
--rm \
--name pusher-build \
--volume "${PWD}":/go/src/github.com/topfreegames/pusher \
pusher:local make build
unit-test-container-dev: build-image-dev
@docker run \
--rm \
--name pusher-test-unit \
--volume "${PWD}":/go/src/github.com/topfreegames/pusher \
pusher:local make test-unit
start-deps-container-dev:
@echo "Starting dependencies..."
@docker compose -f docker-compose-container-dev.yml --project-name pusher up --wait --renew-anon-volumes
@echo "Dependencies started successfully."
integration-test-container-dev: build-image-dev start-deps-container-dev test-db-drop test-db-create
@docker run \
--rm \
--name pusher-test-integration \
--network pusher_default \
--volume "${PWD}":/go/src/github.com/topfreegames/pusher \
-e CONFIG_FILE="../config/docker_test.yaml" \
pusher:local make run-integration-test
@$(MAKE) stop-deps
.PHONY: mocks
mocks:
$(MOCKGENERATE) -source=interfaces/client.go -destination=mocks/interfaces/client.go
$(MOCKGENERATE) -source=interfaces/apns.go -destination=mocks/interfaces/apns.go
$(MOCKGENERATE) -source=interfaces/statsd.go -destination=mocks/interfaces/statsd.go
$(MOCKGENERATE) -source=interfaces/stats_reporter.go -destination=mocks/interfaces/stats_reporter.go
$(MOCKGENERATE) -source=interfaces/feedback_reporter.go -destination=mocks/interfaces/feedback_reporter.go
$(MOCKGENERATE) -source=interfaces/message_handler.go -destination=mocks/interfaces/message_handler.go
$(MOCKGENERATE) -source=interfaces/rate_limiter.go -destination=mocks/interfaces/rate_limiter.go