refactor: add general-purpose test-mode signal in internal/test

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 <mbuevans@gmail.com>
pull/32169/head
Evans Mungai 1 week ago
parent e8b053d999
commit 24e03e3dab
No known key found for this signature in database
GPG Key ID: BBEB812143DD14E1

@ -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)

@ -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

@ -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
Loading…
Cancel
Save