From 3d779f23c30018cf1bf4a6415752d2cc2c37f75d Mon Sep 17 00:00:00 2001 From: James Payne Date: Wed, 23 Apr 2025 22:50:51 +0100 Subject: [PATCH] Move test framework into sharable internal package Signed-off-by: James Payne --- .../logging/test/capture_handler.go | 2 +- pkg/chart/v2/util/coalesce_test.go | 23 ++++++++++--------- 2 files changed, 13 insertions(+), 12 deletions(-) rename pkg/chart/v2/util/utilities_test.go => internal/logging/test/capture_handler.go (99%) diff --git a/pkg/chart/v2/util/utilities_test.go b/internal/logging/test/capture_handler.go similarity index 99% rename from pkg/chart/v2/util/utilities_test.go rename to internal/logging/test/capture_handler.go index da6b51d67..93156a213 100644 --- a/pkg/chart/v2/util/utilities_test.go +++ b/internal/logging/test/capture_handler.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package util +package test import ( "context" diff --git a/pkg/chart/v2/util/coalesce_test.go b/pkg/chart/v2/util/coalesce_test.go index 3da7f7106..cfc3a0b14 100644 --- a/pkg/chart/v2/util/coalesce_test.go +++ b/pkg/chart/v2/util/coalesce_test.go @@ -23,6 +23,7 @@ import ( "github.com/stretchr/testify/assert" + capture_handler "helm.sh/helm/v4/internal/logging/test" chart "helm.sh/helm/v4/pkg/chart/v2" ) @@ -704,7 +705,7 @@ func TestCoalesceValuesWarnings(t *testing.T) { // Get all logs emitted from slog defaultLogger := slog.Default() - handler := NewLogCaptureHandler(nil) + handler := capture_handler.NewLogCaptureHandler(nil) slog.SetDefault(slog.New(handler)) _, err := coalesce(c, vals, "", false) @@ -719,30 +720,30 @@ func TestCoalesceValuesWarnings(t *testing.T) { t.Logf("logs: %s", capturedLogOutput.String()) // All warnings should have context as to where the warning is being emitted - capturedLogOutput.Filter(RecordLevelMatches(slog.LevelWarn)). + capturedLogOutput.Filter(capture_handler.RecordLevelMatches(slog.LevelWarn)). AssertThat(t). HasAttr("chart"). HasAttr("error"). HasAttr("key") - capturedLogOutput.Filter(RecordMessageMatches("skipping key")). - Filter(RecordHasAttrValue("key", "level1.level2.level3.boat")). + capturedLogOutput.Filter(capture_handler.RecordMessageMatches("skipping key")). + Filter(capture_handler.RecordHasAttrValue("key", "level1.level2.level3.boat")). AssertThat(t). MatchesExactly(1). AtLevel(slog.LevelWarn). HasAttrValueString("chart", "level3"). HasAttrValueString("error", "cannot merge table and non-table values") - capturedLogOutput.Filter(RecordMessageMatches("skipping key")). - Filter(RecordHasAttrValue("key", "level1.level2.level3.spear.tip")). + capturedLogOutput.Filter(capture_handler.RecordMessageMatches("skipping key")). + Filter(capture_handler.RecordHasAttrValue("key", "level1.level2.level3.spear.tip")). AssertThat(t). MatchesExactly(1). AtLevel(slog.LevelWarn). HasAttrValueString("chart", "level3"). HasAttrValueString("error", "cannot merge table and non-table values") - capturedLogOutput.Filter(RecordMessageMatches("skipping key")). - Filter(RecordHasAttrValue("key", "level1.level2.level3.spear.sail")). + capturedLogOutput.Filter(capture_handler.RecordMessageMatches("skipping key")). + Filter(capture_handler.RecordHasAttrValue("key", "level1.level2.level3.spear.sail")). AssertThat(t). MatchesExactly(1). AtLevel(slog.LevelWarn). @@ -785,7 +786,7 @@ func TestCoalesceValuesTopLevelGlobalsWarningsSrc(t *testing.T) { // Get all logs emitted from slog defaultLogger := slog.Default() - handler := NewLogCaptureHandler(nil) + handler := capture_handler.NewLogCaptureHandler(nil) slog.SetDefault(slog.New(handler)) _, err := coalesce(c, vals, "", false) @@ -800,13 +801,13 @@ func TestCoalesceValuesTopLevelGlobalsWarningsSrc(t *testing.T) { t.Logf("logs: %s", capturedLogOutput.String()) // All warnings should have context as to where the warning is being emitted - capturedLogOutput.Filter(RecordLevelMatches(slog.LevelWarn)). + capturedLogOutput.Filter(capture_handler.RecordLevelMatches(slog.LevelWarn)). AssertThat(t). HasAttr("chart"). HasAttr("error"). HasAttr("key") - capturedLogOutput.Filter(RecordMessageMatches("skipping coalescing global values")). + capturedLogOutput.Filter(capture_handler.RecordMessageMatches("skipping coalescing global values")). AssertThat(t). MatchesExactly(1). AtLevel(slog.LevelWarn).