-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakefile
87 lines (71 loc) · 2.61 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
cache?=1
dev?=0
DB_URL?="postgresql://$(DB_USER):$(DB_PASSWORD)@localhost:$(DB_PORT)/$(DB_DATABASE)?sslmode=disable"
ifeq ($(dev), 1)
DB_URL="postgresql://postgres:secret@localhost:5432/golang_masterclass?sslmode=disable"
endif
DB_start:
$(shell /bin/sh ./.scripts/postgres.sh);
DB_stop:
docker stop postgres10
createdb:
docker exec -it postgres10 createdb --username=postgres --owner=postgres golang_masterclass
dropdb:
docker exec -it postgres10 dropdb golang_masterclass
migrateup:
migrate -path db/sql/postgresql/migration -database $(DB_URL) -verbose up
migrateup1:
migrate -path db/sql/postgresql/migration -database $(DB_URL) -verbose up 1
migratedown:
migrate -path db/sql/postgresql/migration -database $(DB_URL) -verbose down
migratedown1:
migrate -path db/sql/postgresql/migration -database $(DB_URL) -verbose down 1
sqlc:
sqlc generate
test_main_db:
@echo "Running tests...."
@echo "Cache is $(cache)"
@if [ "$(cache)" = 1 ]; then \
go test -timeout 30s -v -cover github.com/vldcreation/simple_bank/db/sql/postgresql/sqlc -run ^TestMain; \
else \
go test -timeout 30s -v -cover -count=1 github.com/vldcreation/simple_bank/db/sql/postgresql/sqlc -run ^TestMain; \
fi
test_create_account:
@echo "Running tests...."
@echo "Cache is $(cache)"
@if [ "$(cache)" = 1 ]; then \
go test -timeout 30s -v -cover github.com/vldcreation/simple_bank/db/sql/postgresql/sqlc -run ^TestCreateAccount; \
else \
go test -timeout 30s -v -cover -count=1 github.com/vldcreation/simple_bank/db/sql/postgresql/sqlc -run ^TestCreateAccount; \
fi
test:
@echo "Running tests...."
@echo "Cache is $(cache)"
@if [ "$(cache)" = 1 ]; then \
rm -f cover.out cover.html && \
go test -v -cover -coverprofile cover.out ./... && \
go tool cover -html cover.out -o cover.html && \
echo "Dev mode is $(debug)" && \
if [ "$(debug)" = 1 ]; then \
open cover.html ; \
fi; \
else \
rm -f cover.out cover.html && \
go test -v -cover -coverprofile cover.out -count=1 ./... && \
go tool cover -html cover.out -o cover.html && \
echo "Dev mode is $(debug)" && \
if [ "$(debug)" = 1 ]; then \
open cover.html ; \
fi; \
fi
install:
@echo "Installing dependencies...."
@rm -rf vendor
@go mod download && go mod tidy && go mod vendor
start:
@echo "Starting server...."
@go run main.go
mock:
@echo "Generating mocks...."
@mockgen -source db/sql/postgresql/sqlc/store.go -destination db/sql/postgresql/mock/store.go -package mockdb -aux_files mockdb=db/sql/postgresql/sqlc/querier.go
.PHONY: DB_start DB_stop createdb dropdb migrateup migrateup1 migratedown migratedown1 sqlc test test_create_account test_main_db install start