#!/usr/bin/make -f

include /usr/share/dpkg/architecture.mk

export DH_GOLANG_EXCLUDES := \
	apptest/ \
	# EOL

export DH_GOLANG_INSTALL_EXTRA := \
	app/vmalert/templates/templates/ \
	app/vmselect/graphite/functions.json \
	lib/httpserver/favicon.ico \
	# EOL

%:
	dh $@ --builddirectory=_build --buildsystem=golang

# Ignore errors due to floating point comparisons w/o epsilon.
ifneq (,$(filter $(DEB_HOST_ARCH),armhf riscv64 s390x))
  TESTS_FLAKY = yes
endif

TESTS_SKIP =

ifneq (,$(filter $(DEB_HOST_ARCH),loong64 ppc64el s390x))
  TESTS_SKIP += TestRollupHoltWinters
endif

ifneq (,$(filter $(DEB_HOST_ARCH),i386 riscv64))
  TESTS_SKIP += TestStorage_futureTimestamps
endif

ifneq (,$(filter $(DEB_HOST_ARCH),armhf i386))
  TESTS_SKIP += TestDecompressLimitedFail
endif

ifneq (,$(filter $(DEB_HOST_ARCH),ppc64el))
  TESTS_SKIP += TestBackoffRetry_Failure
endif

# Ignore specific test that fail only during autopkgtest.
ifneq (,$(AUTOPKGTEST_TMP))
  TESTS_SKIP += TestExecSuccess
  TESTS_SKIP += TestExecError
endif

ifneq (,$(TESTS_SKIP))
  TESTS_SKIP_OPT = -skip '$(subst $(eval ) ,|,$(TESTS_SKIP))'
  TESTS_FLAKY_RUN_OPT = -run '$(subst $(eval ) ,|,$(TESTS_SKIP))'
endif

override_dh_auto_test:
ifeq ($(TESTS_FLAKY),yes)
	@echo "Notice: Running tests in flaky mode, errors will be ignored."
endif
	$(if $(TESTS_FLAKY),-)dh_auto_test -- $(TESTS_SKIP_OPT)
	-dh_auto_test -- $(TESTS_FLAKY_RUN_OPT)
