From 45884fb000399181aa484c36c7c50cc529e5eb86 Mon Sep 17 00:00:00 2001 From: Arthur Pitman Date: Thu, 30 Jan 2025 08:51:02 +0100 Subject: [PATCH] test: Fix MONACO_LOG_FORMAT environment variable in test --- internal/log/log_test.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/internal/log/log_test.go b/internal/log/log_test.go index 09c8d69b7..9b05cf118 100644 --- a/internal/log/log_test.go +++ b/internal/log/log_test.go @@ -28,6 +28,7 @@ import ( "github.com/spf13/afero" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/dynatrace/dynatrace-configuration-as-code/v2/internal/log/field" "github.com/dynatrace/dynatrace-configuration-as-code/v2/internal/testutils" @@ -135,7 +136,7 @@ func TestPrepareLogFile_ReturnsErrIfParentDirIsReadOnly(t *testing.T) { func TestWithFields(t *testing.T) { logSpy := bytes.Buffer{} - t.Setenv("MONACO_LOG_FORMAT", "true") + t.Setenv("MONACO_LOG_FORMAT", "json") PrepareLogging(afero.NewOsFs(), false, &logSpy, false) WithFields( @@ -146,7 +147,7 @@ func TestWithFields(t *testing.T) { var data map[string]interface{} err := json.Unmarshal(logSpy.Bytes(), &data) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "Logging with fields", data["msg"]) assert.Equal(t, "Captain", data["Title"]) assert.Equal(t, "Iglo", data["Name"]) @@ -161,7 +162,7 @@ func TestWithFields(t *testing.T) { func TestFromCtx(t *testing.T) { logSpy := bytes.Buffer{} - t.Setenv("MONACO_LOG_FORMAT", "true") + t.Setenv("MONACO_LOG_FORMAT", "json") PrepareLogging(afero.NewOsFs(), false, &logSpy, false) c := coordinate.Coordinate{Project: "p1", Type: "t1", ConfigId: "c1"} @@ -173,7 +174,7 @@ func TestFromCtx(t *testing.T) { var data map[string]interface{} err := json.Unmarshal(logSpy.Bytes(), &data) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "Hi with context", data["msg"]) assert.Equal(t, "p1", data["coordinate"].(map[string]interface{})["project"]) assert.Equal(t, "t1", data["coordinate"].(map[string]interface{})["type"])