...
1
2GOLANGCI_LINT_VERSION=v1.48.0
3
4LINTER=./bin/golangci-lint
5LINTER_VERSION_FILE=./bin/.golangci-lint-version-$(GOLANGCI_LINT_VERSION)
6
7TEST_BINARY=./go-server-sdk.test
8ALLOCATIONS_LOG=./build/allocations.out
9
10OUTPUT_DIR=./build
11
12ALL_SOURCES := $(shell find * -type f -name "*.go")
13
14COVERAGE_PROFILE_RAW=./build/coverage_raw.out
15COVERAGE_PROFILE_RAW_HTML=./build/coverage_raw.html
16COVERAGE_PROFILE_FILTERED=./build/coverage.out
17COVERAGE_PROFILE_FILTERED_HTML=./build/coverage.html
18COVERAGE_ENFORCER_FLAGS=-package github.com/launchdarkly/go-server-sdk/v6 \
19 -skipfiles '(internal/sharedtest/$(COVERAGE_ENFORCER_SKIP_FILES_EXTRA))' \
20 -skipcode "// COVERAGE" \
21 -packagestats -filestats -showcode
22
23.PHONY: build clean test test-coverage benchmarks benchmark-allocs lint
24
25build:
26 go build ./...
27
28clean:
29 go clean
30
31test:
32 go test -run=not-a-real-test ./... # just ensures that the tests compile
33 go test -v -race ./...
34 @# The proxy tests must be run separately because Go caches the global proxy environment variables. We use
35 @# build tags to isolate these tests from the main test run so that if you do "go test ./..." you won't
36 @# get unexpected errors.
37 for tag in proxytest1 proxytest2; do go test -race -v -tags=$$tag ./proxytest; done
38
39test-coverage: $(COVERAGE_PROFILE_RAW)
40 go run github.com/launchdarkly-labs/go-coverage-enforcer@latest $(COVERAGE_ENFORCER_FLAGS) -outprofile $(COVERAGE_PROFILE_FILTERED) $(COVERAGE_PROFILE_RAW)
41 go tool cover -html $(COVERAGE_PROFILE_FILTERED) -o $(COVERAGE_PROFILE_FILTERED_HTML)
42 go tool cover -html $(COVERAGE_PROFILE_RAW) -o $(COVERAGE_PROFILE_RAW_HTML)
43
44$(COVERAGE_PROFILE_RAW): $(ALL_SOURCES)
45 @mkdir -p ./build
46 go test -coverprofile $(COVERAGE_PROFILE_RAW) -coverpkg=./... ./... >/dev/null
47 # note that -coverpkg=./... is necessary so it aggregates coverage to include inter-package references
48
49benchmarks:
50 @mkdir -p ./build
51 go test -benchmem '-run=^$$' -bench . ./... | tee build/benchmarks.out
52 @if grep <build/benchmarks.out 'NoAlloc.*[1-9][0-9]* allocs/op'; then echo "Unexpected heap allocations detected in benchmarks!"; exit 1; fi
53
54# See CONTRIBUTING.md regarding the use of the benchmark-allocs target. Notes about this implementation:
55# 1. We precompile the test code because otherwise the allocation traces will include the actions of the compiler itself.
56# 2. "benchtime=3x" means the run count (b.N) is set to 3. Setting it to 1 would produce less redundant output, but the
57# benchmark statistics seem to be less reliable if the run count is less than 3 - they will report a higher allocation
58# count per run, possibly because the first run
59benchmark-allocs:
60 @if [ -z "$$BENCHMARK" ]; then echo "must specify BENCHMARK=" && exit 1; fi
61 @mkdir -p $(OUTPUT_DIR)
62 @echo Precompiling test code to $(TEST_BINARY)
63 @go test -c -o $(TEST_BINARY) >/dev/null 2>&1
64 @echo "Generating heap allocation traces in $(ALLOCATIONS_LOG) for benchmark(s): $$BENCHMARK"
65 @echo "You should see some benchmark result output; if you do not, you may have misspelled the benchmark name/regex"
66 @GODEBUG=allocfreetrace=1 LD_TEST_ALLOCATIONS= $(TEST_BINARY) -test.run=none -test.bench=$$BENCHMARK -test.benchmem -test.benchtime=1x 2>$(ALLOCATIONS_LOG)
67
68$(LINTER_VERSION_FILE):
69 rm -f $(LINTER)
70 curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s $(GOLANGCI_LINT_VERSION)
71 touch $(LINTER_VERSION_FILE)
72
73lint: $(LINTER_VERSION_FILE)
74 $(LINTER) run ./...
75
76
77TEMP_TEST_OUTPUT=/tmp/sse-contract-test-service.log
78
79# TEST_HARNESS_PARAMS can be set to add -skip parameters for any contract tests that cannot yet pass
80TEST_HARNESS_PARAMS=
81
82build-contract-tests:
83 @cd testservice && go mod tidy && go build
84
85start-contract-test-service: build-contract-tests
86 @./testservice/testservice
87
88start-contract-test-service-bg:
89 @echo "Test service output will be captured in $(TEMP_TEST_OUTPUT)"
90 @make start-contract-test-service >$(TEMP_TEST_OUTPUT) 2>&1 &
91
92run-contract-tests:
93 @curl -s https://raw.githubusercontent.com/launchdarkly/sdk-test-harness/v2/downloader/run.sh \
94 | VERSION=v2 PARAMS="-url http://localhost:8000 -debug -stop-service-at-end $(TEST_HARNESS_PARAMS)" sh
95
96contract-tests: build-contract-tests start-contract-test-service-bg run-contract-tests
97
98.PHONY: build-contract-tests start-contract-test-service start-contract-test-service-bg run-contract-tests contract-tests
View as plain text