.PHONY: all precommit setup lint test integration_test build run fix jenkins
SELF_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
include $(SELF_DIR)CommonMakefile.mk

MAIN_DIR ?= $(LOCAL_PACKAGES)
XNET_REV ?= master
GOJI_REV ?= origin/net-context
SERVICE_COMMON_REV ?= master
GOTEST ?= .

get:
	# This is a library so we can't use vendored packages.
	# Instead run `go get` so we can use them in the tests.
	$(call go_get_rev,"golang.org/x/net",$(XNET_REV)) # for goji
	$(call go_get_rev,"goji.io",$(GOJI_REV))
	$(call go_get_rev,"code.justin.tv/feeds/service-common",$(SERVICE_COMMON_REV)) # this is a hack for goimports failing to match the service-common repo with service_common package
	go get -t ./...

integration_test: duplo_integration_test fanout_integration_test masonry_integration_test shine_integration_test edge_integration_test feed-settings_integration_test feedsedge_integration_test

# Separate the tests so we can run them via os.Exec() during duplo's own integration test
duplo_integration_test:
	env ENVIRONMENT=$(ENVIRONMENT) go test -race -tags=integration -run=$(GOTEST) -timeout 30s -v ./duplo/...

fanout_integration_test:
	env ENVIRONMENT=$(ENVIRONMENT) go test -race -tags=integration -run=$(GOTEST) -timeout 30s -v ./fanout/...

masonry_integration_test:
	env ENVIRONMENT=$(ENVIRONMENT) go test -race -tags=integration -run=$(GOTEST) -timeout 30s -v ./masonry/...

shine_integration_test:
	env ENVIRONMENT=$(ENVIRONMENT) go test -race -tags=integration -run=$(GOTEST) -timeout 30s -v ./shine/...

edge_integration_test:
	env ENVIRONMENT=$(ENVIRONMENT) go test -race -tags=integration -run=$(GOTEST) -timeout 30s -v ./edge/...

feedsedge_integration_test:
	env ENVIRONMENT=$(ENVIRONMENT) go test -race -tags=integration -run=$(GOTEST) -timeout 30s -v ./feedsedge/...

feed-settings_integration_test:
	env ENVIRONMENT=$(ENVIRONMENT) go test -race -tags=integration -run=$(GOTEST) -timeout 30s -v ./feed-settings/...

jenkins: setup get lint test build
	go env
	go version
	env
	mkdir /build/output
	touch /build/output/.keep
