fleet/tools/github-manage/pkg/logger/logger_test.go
George Karr df5e42a54c
Github Manager (#31540)
New tool to help with github management. Read all about it in the
[README](https://github.com/fleetdm/fleet/blob/gkarr-gm/tools/github-manage/README.md)
on this branch.
2025-08-07 15:00:36 -05:00

53 lines
1.3 KiB
Go

package logger
import (
"bytes"
"testing"
"strings"
)
func TestLogger(t *testing.T) {
// Create a buffer to capture log output
var buf bytes.Buffer
// Initialize logger with test buffer
if err := Init(); err != nil {
t.Fatalf("Failed to initialize logger: %v", err)
}
// Override the output to use our buffer for testing
SetOutput(&buf)
// Test various log levels
Info("This is an info message")
Infof("This is an info message with value: %d", 42)
Error("This is an error message")
Errorf("This is an error message with error: %v", "test error")
Debug("This is a debug message")
Debugf("This is a debug message with data: %s", "test data")
// Check that output was written
output := buf.String()
if len(output) == 0 {
t.Error("No output was written to the logger")
}
// Check that all message types are present
if !strings.Contains(output, "INFO:") {
t.Error("INFO message not found in output")
}
if !strings.Contains(output, "ERROR:") {
t.Error("ERROR message not found in output")
}
if !strings.Contains(output, "DEBUG:") {
t.Error("DEBUG message not found in output")
}
// Check specific content
if !strings.Contains(output, "This is an info message") {
t.Error("Info message content not found")
}
if !strings.Contains(output, "value: 42") {
t.Error("Formatted info message content not found")
}
}