github.com/machinefi/w3bstream@v1.6.5-rc9.0.20240426031326-b8c7c4876e72/pkg/depends/Makefile (about) 1 MODULE_NAME = $(shell cat go.mod | grep "^module" | sed -e "s/module //g") 2 TOOLKIT_PKG = ${MODULE_NAME}/gen/cmd/toolkit 3 4 install_toolkit: 5 @go install "${TOOLKIT_PKG}/..." 6 7 ## TODO add source format as a githook 8 format: install_toolkit 9 go mod tidy 10 toolkit fmt 11 12 generate: install_toolkit 13 go mod tidy 14 go generate ./... 15 toolkit fmt 16 17 18 export PG_TEST_DB_NAME=test 19 export PG_TEST_DB_USER=test_user 20 export PG_TEST_DB_PASSWD=test_passwd 21 export PG_TEST_HOSTNAME='postgres://$(PG_TEST_DB_USER):$(PG_TEST_DB_PASSWD)@127.0.0.1:5432' 22 export PG_TEST_MASTER_EP='$(PG_TEST_HOSTNAME)/$(PG_TEST_DB_NAME)' 23 export PG_TEST_SLAVE_EP=$(PG_TEST_HOSTNAME) 24 25 26 pg_envs: 27 @echo "=== print env variable ===" 28 @echo 'PG_TEST_DB_NAME = $(PG_TEST_DB_NAME)' 29 @echo 'PG_TEST_DB_USER = $(PG_TEST_DB_USER)' 30 @echo 'PG_TEST_DB_PASSWD = $(PG_TEST_DB_PASSWD)' 31 @echo 'PG_TEST_HOSTNAME = $(PG_TEST_HOSTNAME)' 32 @echo 'PG_TEST_MASTER_EP = $(PG_TEST_MASTER_EP)' 33 @echo 'PG_TEST_SLAVE_EP = $(PG_TEST_SLAVE_EP)' 34 @echo "=== print env variable end ===\n" 35 36 pg_start: 37 @if [[ $$(pg_isready -h localhost) != "localhost:5432 - accepting connections" ]] ; \ 38 then \ 39 echo "=== start postgres server ==="; \ 40 docker-compose -f testutil/docker-compose-pg.yaml up -d ; \ 41 echo "=== init database ===" ; \ 42 for i in {1..5} ; \ 43 do \ 44 if [[ $$(pg_isready -h localhost) =~ "accepting connections" ]] ; \ 45 then \ 46 psql $(PG_TEST_HOSTNAME) -c 'create database $(PG_TEST_DB_NAME)' && \ 47 psql $(PG_TEST_HOSTNAME) -c 'create schema $(PG_TEST_DB_NAME)' ; \ 48 break ; \ 49 else \ 50 echo "server not ready, retry in 10 second" ; sleep 10 ; \ 51 fi \ 52 done ; \ 53 if [[ $$(pg_isready -h localhost) != "localhost:5432 - accepting connections" ]] ; \ 54 then \ 55 echo "=== database init failed ===" ; \ 56 exit 1; \ 57 fi \ 58 fi ; \ 59 60 run_depends: 61 @docker-compose -f testutil/docker-compose-redis.yaml up -d 62 @docker-compose -f testutil/docker-compose-pg.yaml up -d 63 @docker-compose -f testutil/docker-compose-mqtt.yaml up -d 64 65 test: 66 go test ./... 67 @echo "=================TEST FINISHED================="