Skip to content

Commit

Permalink
logger_test: use asserts
Browse files Browse the repository at this point in the history
  • Loading branch information
gi8lino committed Jan 14, 2025
1 parent 4dc35d2 commit 827959e
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions internal/logging/logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package logging
import (
"strings"
"testing"

"github.com/stretchr/testify/assert"
)

func TestSetupLogger(t *testing.T) {
Expand All @@ -16,20 +18,12 @@ func TestSetupLogger(t *testing.T) {
version := "1.0.0"

logger := SetupLogger(version, &output)
if logger == nil {
t.Fatalf("Expected a logger instance, got nil")
}
assert.NotNil(t, logger)

logger.Info("Test log message")

logOutput := output.String()
if !strings.Contains(logOutput, "Test log message") {
t.Errorf("Expected log output to contain 'Test log message', got %q", logOutput)
}

if !strings.Contains(logOutput, "version=1.0.0") {
t.Errorf("Expected log output to contain 'version=1.0.0', got %q", logOutput)
}
assert.Contains(t, logOutput, "Test log message")
assert.Contains(t, logOutput, "version=1.0.0")
})

// Test that the logger writes output to the correct writer.
Expand All @@ -40,15 +34,11 @@ func TestSetupLogger(t *testing.T) {
version := "2.0.0"

logger := SetupLogger(version, &output)
if logger == nil {
t.Fatalf("Expected a logger instance, got nil")
}
assert.NotNil(t, logger)

logger.Warn("This is a warning")

logOutput := output.String()
if !strings.Contains(logOutput, "This is a warning") {
t.Errorf("Expected log output to contain 'This is a warning', got %q", logOutput)
}
assert.Contains(t, logOutput, "This is a warning")
})
}

0 comments on commit 827959e

Please sign in to comment.