Skip to content

Commit

Permalink
pkg/topology: perform colonoscopy on testdata.
Browse files Browse the repository at this point in the history
While we can use fake go.mod files to prevent golang tooling
from descending into test data directories that contain files
with a ':' in their name, this is not enough. There are other
tools, unfortunately hosted on non-unix OSes that do not like
':'s in file names. Cloning the repository fails on these and
prevents the hosted tools from working at all.

As a workaround, hide offending (test data) files in tarballs
and introduce unit test setup and cleanup hooks to extract
these tarballs on demand.

Signed-off-by: Krisztian Litkey <krisztian.litkey@intel.com>
  • Loading branch information
klihub committed Apr 24, 2023
1 parent 01c6ef9 commit 60cf77b
Show file tree
Hide file tree
Showing 14 changed files with 28 additions and 14 deletions.
28 changes: 26 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ TEST_TAGS := noavx,test
GO_TEST := $(GO_CMD) test $(GO_PARALLEL) -tags $(TEST_TAGS)
GO_VET := $(GO_CMD) vet -tags $(TEST_TAGS)

TEST_SETUP := test-setup.sh
TEST_CLEANUP := test-cleanup.sh

# Disable some golangci_lint checkers for now until we have an more acceptable baseline...
GO_CILINT_CHECKERS := -D unused,staticcheck,errcheck,deadcode,structcheck,gosimple -E revive,gofmt
GO_CILINT_RUNFLAGS := --build-tags $(TEST_TAGS)
Expand Down Expand Up @@ -431,7 +434,28 @@ shellcheck:
# Rules for running unit/module tests.
#

test:
test: test-setup test-run test-cleanup
race-test racetest: test-setup racetest-run test-cleanup

test-setup:
$(Q)for i in $$(find . -name $(TEST_SETUP)); do \
echo "+ Running test setup $$i..."; \
(cd $${i%/*}; \
if [ -x "$(TEST_SETUP)" ]; then \
./$(TEST_SETUP); \
fi); \
done

test-cleanup:
$(Q)for i in $$(find . -name $(TEST_CLEANUP)); do \
echo "- Running test cleanup $$i..."; \
(cd $${i%/*}; \
if [ -x "$(TEST_CLEANUP)" ]; then \
./$(TEST_CLEANUP); \
fi); \
done

test-run:
ifndef WHAT
$(Q)$(GO_TEST) -race -coverprofile=coverage.txt -covermode=atomic \
$(shell $(GO_LIST_MODULES))
Expand All @@ -447,7 +471,7 @@ else
exit $$rc
endif

race-test racetest:
racetest-run:
ifndef WHAT
$(Q)$(GO_TEST) -race -coverprofile=coverage.txt -covermode=atomic \
$(shell $(GO_LIST_MODULES))
Expand Down
1 change: 1 addition & 0 deletions pkg/topology/test-cleanup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rm -fr testdata
Binary file added pkg/topology/test-data.tar.gz
Binary file not shown.
1 change: 1 addition & 0 deletions pkg/topology/test-setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tar -xvzf test-data.tar.gz
3 changes: 0 additions & 3 deletions pkg/topology/testdata/go.mod

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit 60cf77b

Please sign in to comment.