From f2c7133525f65f7e6d5aa07ecddb7e85d007b70e Mon Sep 17 00:00:00 2001 From: Alexander Yastrebov Date: Wed, 12 Jul 2023 00:30:36 +0200 Subject: [PATCH] build: simplify go commands Use ./... instead of loop over packages. Originally loop over packages was added by #359 that introduced glide package manager. This manager fetches dependencies into vendor/ subdirectory (see https://glide.readthedocs.io/en/latest/getting-started/) and apparently loop over packages was necessary back then. glide usage was removed by #764 The change now also runs testable examples. Also: * fixes cmd/eskip etcd shutdown similar to #2359 * fixes cmd/eskip test introduced by #2202 * fixes lua example * removed bench target as it makes little sense * .coverprofile-all can not be simplified yet due to https://github.com/golang/go/issues/45361 Signed-off-by: Alexander Yastrebov --- Makefile | 43 +++++++---------------------------------- cmd/eskip/args_test.go | 2 +- cmd/eskip/write_test.go | 16 +++++++-------- script/options_test.go | 1 + 4 files changed, 17 insertions(+), 45 deletions(-) diff --git a/Makefile b/Makefile index bd01017f67..3cdbc6ae8c 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -SOURCES = $(shell find . -name '*.go' -not -path "./vendor/*" -and -not -path "./_test_plugins" -and -not -path "./_test_plugins_fail" ) +SOURCES = $(shell find . -name '*.go' -and -not -path "./_test_plugins" -and -not -path "./_test_plugins_fail" ) PACKAGES = $(shell go list ./...) CURRENT_VERSION = $(shell git describe --tags --always --dirty) VERSION ?= $(CURRENT_VERSION) @@ -20,7 +20,7 @@ help: ## Display this help .PHONY: lib lib: $(SOURCES) ## build skipper library - go build $(PACKAGES) + go build ./... .PHONY: bindir bindir: @@ -79,39 +79,19 @@ install: $(SOURCES) ## install skipper and eskip binaries into your system .PHONY: check check: build check-plugins ## run all tests - # go test $(PACKAGES) - # - # due to vendoring and how go test ./... is not the same as go test ./a/... ./b/... - # probably can be reverted once etcd is fully mocked away for tests - # - for p in $(PACKAGES); do go test $$p || break; done + go test ./... .PHONY: shortcheck shortcheck: build check-plugins fixlimits ## run all short tests - # go test -test.short -run ^Test $(PACKAGES) - # - # due to vendoring and how go test ./... is not the same as go test ./a/... ./b/... - # probably can be reverted once etcd is fully mocked away for tests - # - for p in $(PACKAGES); do go test -test.short -run ^Test $$p || break -1; done + go test -test.short ./... .PHONY: cicheck cicheck: build check-plugins ## run all short and redis tests - # go test -test.short -run ^Test $(PACKAGES) - # - # due to vendoring and how go test ./... is not the same as go test ./a/... ./b/... - # probably can be reverted once etcd is fully mocked away for tests - # - for p in $(PACKAGES); do go test -tags=redis -test.short -run ^Test $$p || break -1; done + go test -tags=redis -test.short ./... .PHONY: check-race -check-race: build ## run all tests with race checker - # go test -race -test.short -run ^Test $(PACKAGES) - # - # due to vendoring and how go test ./... is not the same as go test ./a/... ./b/... - # probably can be reverted once etcd is fully mocked away for tests - # - for p in $(PACKAGES); do go test -race -test.short -run ^Test $$p || break -1; done +check-race: build ## run all short tests with race checker + go test -race -test.short ./... .PHONY: check-plugins check-plugins: $(TEST_PLUGINS) @@ -123,15 +103,6 @@ _test_plugins/%.so: _test_plugins/%.go _test_plugins_fail/%.so: _test_plugins_fail/%.go go build -buildmode=plugin -o $@ $< -.PHONY: bench -bench: build $(TEST_PLUGINS) ## run all benchmark tests - # go test -bench . $(PACKAGES) - # - # due to vendoring and how go test ./... is not the same as go test ./a/... ./b/... - # probably can be reverted once etcd is fully mocked away for tests - # - for p in $(PACKAGES); do go test -bench . $$p; done - .PHONY: fuzz fuzz: ## run all fuzz tests for p in $(PACKAGES); do go test -run=NONE -fuzz=Fuzz -fuzztime 30s $$p; done diff --git a/cmd/eskip/args_test.go b/cmd/eskip/args_test.go index dbe8b7ba8f..fc714e2250 100644 --- a/cmd/eskip/args_test.go +++ b/cmd/eskip/args_test.go @@ -81,7 +81,7 @@ func TestProcessArgs(t *testing.T) { []string{"-sort-predicates"}, false, nil, - []*medium{{typ: inline, eskip: `PathRegexp("^/") && Host("^(www[.]example[.]org[.]?(:[0-9]+)?)$") -> "https://www.example.org"`}}, + nil, }, { // etcd-urls diff --git a/cmd/eskip/write_test.go b/cmd/eskip/write_test.go index 828f5abe6a..47699cc20e 100644 --- a/cmd/eskip/write_test.go +++ b/cmd/eskip/write_test.go @@ -37,13 +37,6 @@ func TestMain(m *testing.M) { log.Fatal(err) } - defer func() { - err := etcdtest.Stop() - if err != nil { - log.Fatal(err) - } - }() - urls, err := stringsToUrls(etcdtest.Urls...) if err != nil { log.Fatal(err) @@ -51,7 +44,14 @@ func TestMain(m *testing.M) { testEtcdUrls = urls - os.Exit(m.Run()) + exitCode := m.Run() + + err = etcdtest.Stop() + if err != nil { + log.Fatal(err) + } + + os.Exit(exitCode) } func TestUpsertLoadFail(t *testing.T) { diff --git a/script/options_test.go b/script/options_test.go index 9af38cd80d..a886db0180 100644 --- a/script/options_test.go +++ b/script/options_test.go @@ -121,6 +121,7 @@ func ExampleLuaOptions_enableModules() { // table // table.insert // table.sort + // package.config // package.cpath // package.loaded // package.loaders