GO := CGO_ENABLED=0 go

HTTP_PROXY ?= socks5://rms-staging.pingcap.net:30081
MYSQL_PROXY ?= socks5h://rms-staging.pingcap.net:30081
GRPC_PROXY ?= socks5h://rms-staging.pingcap.net:30081

.PHONY: test

test: install-ginkgo
	# for example: export HTTP_PROXY=socks5://172.16.4.67:30081 MYSQL_PROXY=socks5h://172.16.4.67:30081
	GRPC_PROXY=$(GRPC_PROXY) HTTP_PROXY=$(HTTP_PROXY) MYSQL_PROXY=$(GRPC_PROXY) ACK_GINKGO_DEPRECATIONS=1.16.4 ginkgo -- -kubeconfig=$(KUBECONFIG) #-ginkgo.focus "TiDBCluster creates with postStart sql script"

build: install-ginkgo
	ACK_GINKGO_DEPRECATIONS=1.16.4 ginkgo build

fmt: groupimports
	go fmt ./...

groupimports: install-goimports
	goimports -w -l -local github.com/pingcap/test-infra .

install-goimports:
ifeq (, $(shell which goimports))
	go install golang.org/x/tools/cmd/goimports@latest
endif

install-ginkgo:
ifeq (, $(shell which ginkgo))
	@{ \
	GO111MODULE=on go install github.com/onsi/ginkgo/ginkgo@latest ;\
	GO111MODULE=on go get github.com/onsi/gomega/... ; \
	}
endif
