Move test framework into sharable internal package

Signed-off-by: James Payne <jamoflaw@gmail.com>
pull/30774/head
James Payne 5 months ago
parent 80304d5494
commit 3d779f23c3

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
package util package test
import ( import (
"context" "context"

@ -23,6 +23,7 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
capture_handler "helm.sh/helm/v4/internal/logging/test"
chart "helm.sh/helm/v4/pkg/chart/v2" chart "helm.sh/helm/v4/pkg/chart/v2"
) )
@ -704,7 +705,7 @@ func TestCoalesceValuesWarnings(t *testing.T) {
// Get all logs emitted from slog // Get all logs emitted from slog
defaultLogger := slog.Default() defaultLogger := slog.Default()
handler := NewLogCaptureHandler(nil) handler := capture_handler.NewLogCaptureHandler(nil)
slog.SetDefault(slog.New(handler)) slog.SetDefault(slog.New(handler))
_, err := coalesce(c, vals, "", false) _, err := coalesce(c, vals, "", false)
@ -719,30 +720,30 @@ func TestCoalesceValuesWarnings(t *testing.T) {
t.Logf("logs: %s", capturedLogOutput.String()) t.Logf("logs: %s", capturedLogOutput.String())
// All warnings should have context as to where the warning is being emitted // 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). AssertThat(t).
HasAttr("chart"). HasAttr("chart").
HasAttr("error"). HasAttr("error").
HasAttr("key") HasAttr("key")
capturedLogOutput.Filter(RecordMessageMatches("skipping key")). capturedLogOutput.Filter(capture_handler.RecordMessageMatches("skipping key")).
Filter(RecordHasAttrValue("key", "level1.level2.level3.boat")). Filter(capture_handler.RecordHasAttrValue("key", "level1.level2.level3.boat")).
AssertThat(t). AssertThat(t).
MatchesExactly(1). MatchesExactly(1).
AtLevel(slog.LevelWarn). AtLevel(slog.LevelWarn).
HasAttrValueString("chart", "level3"). HasAttrValueString("chart", "level3").
HasAttrValueString("error", "cannot merge table and non-table values") HasAttrValueString("error", "cannot merge table and non-table values")
capturedLogOutput.Filter(RecordMessageMatches("skipping key")). capturedLogOutput.Filter(capture_handler.RecordMessageMatches("skipping key")).
Filter(RecordHasAttrValue("key", "level1.level2.level3.spear.tip")). Filter(capture_handler.RecordHasAttrValue("key", "level1.level2.level3.spear.tip")).
AssertThat(t). AssertThat(t).
MatchesExactly(1). MatchesExactly(1).
AtLevel(slog.LevelWarn). AtLevel(slog.LevelWarn).
HasAttrValueString("chart", "level3"). HasAttrValueString("chart", "level3").
HasAttrValueString("error", "cannot merge table and non-table values") HasAttrValueString("error", "cannot merge table and non-table values")
capturedLogOutput.Filter(RecordMessageMatches("skipping key")). capturedLogOutput.Filter(capture_handler.RecordMessageMatches("skipping key")).
Filter(RecordHasAttrValue("key", "level1.level2.level3.spear.sail")). Filter(capture_handler.RecordHasAttrValue("key", "level1.level2.level3.spear.sail")).
AssertThat(t). AssertThat(t).
MatchesExactly(1). MatchesExactly(1).
AtLevel(slog.LevelWarn). AtLevel(slog.LevelWarn).
@ -785,7 +786,7 @@ func TestCoalesceValuesTopLevelGlobalsWarningsSrc(t *testing.T) {
// Get all logs emitted from slog // Get all logs emitted from slog
defaultLogger := slog.Default() defaultLogger := slog.Default()
handler := NewLogCaptureHandler(nil) handler := capture_handler.NewLogCaptureHandler(nil)
slog.SetDefault(slog.New(handler)) slog.SetDefault(slog.New(handler))
_, err := coalesce(c, vals, "", false) _, err := coalesce(c, vals, "", false)
@ -800,13 +801,13 @@ func TestCoalesceValuesTopLevelGlobalsWarningsSrc(t *testing.T) {
t.Logf("logs: %s", capturedLogOutput.String()) t.Logf("logs: %s", capturedLogOutput.String())
// All warnings should have context as to where the warning is being emitted // 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). AssertThat(t).
HasAttr("chart"). HasAttr("chart").
HasAttr("error"). HasAttr("error").
HasAttr("key") HasAttr("key")
capturedLogOutput.Filter(RecordMessageMatches("skipping coalescing global values")). capturedLogOutput.Filter(capture_handler.RecordMessageMatches("skipping coalescing global values")).
AssertThat(t). AssertThat(t).
MatchesExactly(1). MatchesExactly(1).
AtLevel(slog.LevelWarn). AtLevel(slog.LevelWarn).

Loading…
Cancel
Save