GO := CGO_ENABLED=0 go

.PHONY: test

test: unit-test e2e-test

unit-test:
	go test -timeout 20m -v -parallel 1 -race ./...

e2e-test:
	make -C e2etest test

dbaasapi_gen: install-swagger
	@echo "It can be found in https://github.com/tidbcloud/core-svc/blob/master/idl/pbgen/proto/central/service.swagger.json and https://github.com/tidbcloud/core-svc/blob/master/idl/pbgen/proto/dataflow/service.swagger.json"
	@echo "Please copy it as docs/central.swagger.json and dataflow.swagger.json"
	rm -rf dbaas_central
	go install github.com/msample/swagger-mixin@latest
	swagger-mixin docs/central.swagger.json docs/dataflow.swagger.json | tee docs/mergedSwagger.json
	swagger generate client -f docs/mergedSwagger.json --name=dbaas_central --client-package=dbaas_central/client --model-package=dbaas_central/models

install-swagger:
ifeq (, $(shell which swagger))
	go install github.com/go-swagger/go-swagger/cmd/swagger@latest
endif

fmt: groupimports
	go fmt ./...

godoc-generate: install-gomarkdoc
	gomarkdoc --repository.url https://github.com/pingcap/test-infra --output README.md ./core/... ./resource/...

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

install-gomarkdoc:
	go install github.com/princjef/gomarkdoc/cmd/gomarkdoc@latest

install-goimports:
ifeq (, $(shell which goimports))
	@{ \
	set -e ;\
	TMP_DIR=$$(mktemp -d) ;\
	cd $$TMP_DIR ;\
	GO111MODULE=on go get golang.org/x/tools/cmd/goimports ;\
	rm -rf $$TMP_DIR ;\
	}
endif

install-linter:
ifeq (, $(shell which golangci-lint))
	go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
endif


lint: install-linter
# only show issues that not exist in main
	golangci-lint run --timeout 5m
