fix(tests): add -shuffle=on -count=2 to test-unit in Makefile, Updated .golangci.yml to support test stability improvements.

Signed-off-by: Victor <ubahakweemeka@gmail.com>
pull/30952/head
Victor 4 months ago
parent 8706c441c4
commit 478df30ae5

@ -1,22 +1,4 @@
formatters:
enable:
- gofmt
- goimports
exclusions:
generated: lax
settings:
gofmt:
simplify: true
goimports:
local-prefixes:
- helm.sh/helm/v4
linters: linters:
default: none
enable: enable:
- depguard - depguard
- dupl - dupl
@ -31,40 +13,25 @@ linters:
- unused - unused
- usestdlibvars - usestdlibvars
exclusions: linters-settings:
generated: lax depguard:
rules:
presets: Main:
- comments deny:
- common-false-positives - pkg: github.com/hashicorp/go-multierror
- legacy desc: "use errors instead"
- std-error-handling - pkg: github.com/pkg/errors
desc: "use errors instead"
rules: [] dupl:
threshold: 400
warn-unused: true gomodguard:
blocked:
settings: modules:
depguard: - github.com/evanphx/json-patch:
rules: recommendations:
Main: - github.com/evanphx/json-patch/v5
deny:
- pkg: github.com/hashicorp/go-multierror issues:
desc: "use errors instead" exclude-use-default: false
- pkg: github.com/pkg/errors
desc: "use errors instead"
dupl:
threshold: 400
gomodguard:
blocked:
modules:
- github.com/evanphx/json-patch:
recommendations:
- github.com/evanphx/json-patch/v5
run: run:
timeout: 10m timeout: 10m
version: "2"

@ -11,17 +11,17 @@ GOBIN = $(shell go env GOPATH)/bin
endif endif
GOX = $(GOBIN)/gox GOX = $(GOBIN)/gox
GOIMPORTS = $(GOBIN)/goimports GOIMPORTS = $(GOBIN)/goimports
GOLANGCI_LINT = $(GOBIN)/golangci-lint
ARCH = $(shell go env GOARCH) ARCH = $(shell go env GOARCH)
ACCEPTANCE_DIR:=../acceptance-testing ACCEPTANCE_DIR:=../acceptance-testing
# To specify the subset of acceptance tests to run. '.' means all tests
ACCEPTANCE_RUN_TESTS=. ACCEPTANCE_RUN_TESTS=.
# go option # go option
PKG := ./... PKG := ./...
TAGS := TAGS :=
TESTS := . TESTS := .
TESTFLAGS := TESTFLAGS := -shuffle=on -count=2
LDFLAGS := -w -s LDFLAGS := -w -s
GOFLAGS := GOFLAGS :=
CGO_ENABLED ?= 0 CGO_ENABLED ?= 0
@ -42,13 +42,11 @@ ifdef VERSION
endif endif
BINARY_VERSION ?= ${GIT_TAG} BINARY_VERSION ?= ${GIT_TAG}
# Only set Version if building a tag or VERSION is set
ifneq ($(BINARY_VERSION),) ifneq ($(BINARY_VERSION),)
LDFLAGS += -X helm.sh/helm/v4/internal/version.version=${BINARY_VERSION} LDFLAGS += -X helm.sh/helm/v4/internal/version.version=${BINARY_VERSION}
endif endif
VERSION_METADATA = unreleased VERSION_METADATA = unreleased
# Clear the "unreleased" string in BuildMetadata
ifneq ($(GIT_TAG),) ifneq ($(GIT_TAG),)
VERSION_METADATA = VERSION_METADATA =
endif endif
@ -58,7 +56,6 @@ LDFLAGS += -X helm.sh/helm/v4/internal/version.gitCommit=${GIT_COMMIT}
LDFLAGS += -X helm.sh/helm/v4/internal/version.gitTreeState=${GIT_DIRTY} LDFLAGS += -X helm.sh/helm/v4/internal/version.gitTreeState=${GIT_DIRTY}
LDFLAGS += $(EXT_LDFLAGS) LDFLAGS += $(EXT_LDFLAGS)
# Define constants based on the client-go version
K8S_MODULES_VER=$(subst ., ,$(subst v,,$(shell go list -f '{{.Version}}' -m k8s.io/client-go))) K8S_MODULES_VER=$(subst ., ,$(subst v,,$(shell go list -f '{{.Version}}' -m k8s.io/client-go)))
K8S_MODULES_MAJOR_VER=$(shell echo $$(($(firstword $(K8S_MODULES_VER)) + 1))) K8S_MODULES_MAJOR_VER=$(shell echo $$(($(firstword $(K8S_MODULES_VER)) + 1)))
K8S_MODULES_MINOR_VER=$(word 2,$(K8S_MODULES_VER)) K8S_MODULES_MINOR_VER=$(word 2,$(K8S_MODULES_VER))
@ -71,25 +68,16 @@ LDFLAGS += -X helm.sh/helm/v4/pkg/chart/v2/util.k8sVersionMinor=$(K8S_MODULES_MI
.PHONY: all .PHONY: all
all: build all: build
# ------------------------------------------------------------------------------
# build
.PHONY: build .PHONY: build
build: $(BINDIR)/$(BINNAME) build: $(BINDIR)/$(BINNAME)
$(BINDIR)/$(BINNAME): $(SRC) $(BINDIR)/$(BINNAME): $(SRC)
CGO_ENABLED=$(CGO_ENABLED) go build $(GOFLAGS) -trimpath -tags '$(TAGS)' -ldflags '$(LDFLAGS)' -o '$(BINDIR)'/$(BINNAME) ./cmd/helm CGO_ENABLED=$(CGO_ENABLED) go build $(GOFLAGS) -trimpath -tags '$(TAGS)' -ldflags '$(LDFLAGS)' -o '$(BINDIR)'/$(BINNAME) ./cmd/helm
# ------------------------------------------------------------------------------
# install
.PHONY: install .PHONY: install
install: build install: build
@install "$(BINDIR)/$(BINNAME)" "$(INSTALL_PATH)/$(BINNAME)" @install "$(BINDIR)/$(BINNAME)" "$(INSTALL_PATH)/$(BINNAME)"
# ------------------------------------------------------------------------------
# test
.PHONY: test .PHONY: test
test: build test: build
ifeq ($(ARCH),s390x) ifeq ($(ARCH),s390x)
@ -107,14 +95,8 @@ test-unit:
go test $(GOFLAGS) -run $(TESTS) $(PKG) $(TESTFLAGS) go test $(GOFLAGS) -run $(TESTS) $(PKG) $(TESTFLAGS)
@echo @echo
@echo "==> Running unit test(s) with ldflags <==" @echo "==> Running unit test(s) with ldflags <=="
# Test to check the deprecation warnings on Kubernetes templates created by `helm create` against the current Kubernetes
# version. Note: The version details are set in var LDFLAGS. To avoid the ldflags impact on other unit tests that are
# based on older versions, this is run separately. When run without the ldflags in the unit test (above) or coverage
# test, it still passes with a false-positive result as the resources shouldnt be deprecated in the older Kubernetes
# version if it only starts failing with the latest.
go test $(GOFLAGS) -run ^TestHelmCreateChart_CheckDeprecatedWarnings$$ ./pkg/lint/ $(TESTFLAGS) -ldflags '$(LDFLAGS)' go test $(GOFLAGS) -run ^TestHelmCreateChart_CheckDeprecatedWarnings$$ ./pkg/lint/ $(TESTFLAGS) -ldflags '$(LDFLAGS)'
.PHONY: test-coverage .PHONY: test-coverage
test-coverage: test-coverage:
@echo @echo
@ -122,8 +104,8 @@ test-coverage:
@ ./scripts/coverage.sh @ ./scripts/coverage.sh
.PHONY: test-style .PHONY: test-style
test-style: test-style: $(GOLANGCI_LINT)
golangci-lint run ./... $(GOLANGCI_LINT) run --timeout 5m ./...
@scripts/validate-license.sh @scripts/validate-license.sh
.PHONY: test-source-headers .PHONY: test-source-headers
@ -153,28 +135,20 @@ coverage:
format: $(GOIMPORTS) format: $(GOIMPORTS)
go list -f '{{.Dir}}' ./... | xargs $(GOIMPORTS) -w -local helm.sh/helm go list -f '{{.Dir}}' ./... | xargs $(GOIMPORTS) -w -local helm.sh/helm
# Generate golden files used in unit tests
.PHONY: gen-test-golden .PHONY: gen-test-golden
gen-test-golden: gen-test-golden:
gen-test-golden: PKG = ./pkg/cmd ./pkg/action gen-test-golden: PKG = ./pkg/cmd ./pkg/action
gen-test-golden: TESTFLAGS = -update gen-test-golden: TESTFLAGS = -update
gen-test-golden: test-unit gen-test-golden: test-unit
# ------------------------------------------------------------------------------
# dependencies
# If go install is run from inside the project directory it will add the
# dependencies to the go.mod file. To avoid that we change to a directory
# without a go.mod file when downloading the following dependencies
$(GOX): $(GOX):
(cd /; go install github.com/mitchellh/gox@v1.0.2-0.20220701044238-9f712387e2d2) (cd /; go install github.com/mitchellh/gox@v1.0.2-0.20220701044238-9f712387e2d2)
$(GOIMPORTS): $(GOIMPORTS):
(cd /; go install golang.org/x/tools/cmd/goimports@latest) (cd /; go install golang.org/x/tools/cmd/goimports@latest)
# ------------------------------------------------------------------------------ $(GOLANGCI_LINT):
# release (cd /; go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.55.2)
.PHONY: build-cross .PHONY: build-cross
build-cross: LDFLAGS += -extldflags "-static" build-cross: LDFLAGS += -extldflags "-static"
@ -205,13 +179,6 @@ sign:
gpg --armor --detach-sign $${f} ; \ gpg --armor --detach-sign $${f} ; \
done done
# The contents of the .sha256sum file are compatible with tools like
# shasum. For example, using the following command will verify
# the file helm-3.1.0-rc.1-darwin-amd64.tar.gz:
# shasum -a 256 -c helm-3.1.0-rc.1-darwin-amd64.tar.gz.sha256sum
# The .sha256 files hold only the hash and are not compatible with
# verification tools like shasum or sha256sum. This method and file can be
# removed in Helm v4.
.PHONY: checksum .PHONY: checksum
checksum: checksum:
for f in $$(ls _dist/*.{gz,zip} 2>/dev/null) ; do \ for f in $$(ls _dist/*.{gz,zip} 2>/dev/null) ; do \
@ -219,30 +186,25 @@ checksum:
shasum -a 256 "$${f}" | awk '{print $$1}' > "$${f}.sha256" ; \ shasum -a 256 "$${f}" | awk '{print $$1}' > "$${f}.sha256" ; \
done done
# ------------------------------------------------------------------------------
.PHONY: clean .PHONY: clean
clean: clean:
@rm -rf '$(BINDIR)' ./_dist @rm -rf '$(BINDIR)' ./_dist
.PHONY: release-notes .PHONY: release-notes
release-notes: release-notes:
@if [ ! -d "./_dist" ]; then \ @if [ ! -d "./_dist" ]; then \
echo "please run 'make fetch-dist' first" && \ echo "please run 'make fetch-dist' first" && \
exit 1; \ exit 1; \
fi fi
@if [ -z "${PREVIOUS_RELEASE}" ]; then \ @if [ -z "${PREVIOUS_RELEASE}" ]; then \
echo "please set PREVIOUS_RELEASE environment variable" \ echo "please set PREVIOUS_RELEASE environment variable" \
&& exit 1; \ && exit 1; \
fi fi
@./scripts/release-notes.sh ${PREVIOUS_RELEASE} ${VERSION}
@./scripts/release-notes.sh ${PREVIOUS_RELEASE} ${VERSION}
.PHONY: info .PHONY: info
info: info:
@echo "Version: ${VERSION}" @echo "Version: ${VERSION}"
@echo "Git Tag: ${GIT_TAG}" @echo "Git Tag: ${GIT_TAG}"
@echo "Git Commit: ${GIT_COMMIT}" @echo "Git Commit: ${GIT_COMMIT}"
@echo "Git Tree State: ${GIT_DIRTY}" @echo "Git Tree State: ${GIT_DIRTY}"
Loading…
Cancel
Save