From 24e03e3dabcf996830ee7037cff8c2fbbe5c0c31 Mon Sep 17 00:00:00 2001 From: Evans Mungai Date: Thu, 28 May 2026 18:21:57 +0100 Subject: [PATCH] refactor: add general-purpose test-mode signal in internal/test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Introduce test.IsTestMode(), backed by a compile-time const seeded by two mutually-exclusive build-tagged files (test_mode_on.go under -tags helmtest, test_mode_off.go otherwise). Branches gated on it dead-code-eliminate in release builds. Available for any production code path that needs to behave differently under test. Not yet consumed — internal/version and pkg/chart/common continue to gate on the KubeVersionMajorTesting / KubeVersionMinorTesting sentinels seeded by internal/version/version_helmtest.go. Signed-off-by: Evans Mungai --- internal/test/test.go | 9 +++++++++ internal/test/test_mode_off.go | 21 +++++++++++++++++++++ internal/test/test_mode_on.go | 21 +++++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 internal/test/test_mode_off.go create mode 100644 internal/test/test_mode_on.go diff --git a/internal/test/test.go b/internal/test/test.go index 202e015ab..e3c5b9c68 100644 --- a/internal/test/test.go +++ b/internal/test/test.go @@ -27,6 +27,15 @@ import ( // UpdateGolden writes out the golden files with the latest values, rather than failing the test. var updateGolden = flag.Bool("update", false, "update golden files") +// IsTestMode reports whether the binary was built with -tags helmtest. +// General-purpose signal that the binary was built for tests; consult it +// from production code paths that need to behave differently under test. +// Backed by a compile-time const (see test_mode_on.go / test_mode_off.go) +// so branches gated on it dead-code-eliminate in release builds. +func IsTestMode() bool { + return testMode +} + // TestingT describes a testing object compatible with the critical functions from the testing.T type type TestingT interface { Fatal(...any) diff --git a/internal/test/test_mode_off.go b/internal/test/test_mode_off.go new file mode 100644 index 000000000..62534ed12 --- /dev/null +++ b/internal/test/test_mode_off.go @@ -0,0 +1,21 @@ +//go:build !helmtest + +/* +Copyright The Helm Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package test + +const testMode = false diff --git a/internal/test/test_mode_on.go b/internal/test/test_mode_on.go new file mode 100644 index 000000000..8a2978699 --- /dev/null +++ b/internal/test/test_mode_on.go @@ -0,0 +1,21 @@ +//go:build helmtest + +/* +Copyright The Helm Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package test + +const testMode = true