Files
mc-god/internal/pkg/logs/logs_test.go
2026-02-13 16:33:49 -08:00

58 lines
1.2 KiB
Go

package logs
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestLogger(t *testing.T) {
// This is a basic test to ensure the structure compiles correctly
// Actual integration testing would require a Kubernetes cluster
logger := Logger{
Deployment: "test-deployment",
Namespace: "test-namespace",
}
// Test that the struct can be created
assert.NotNil(t, logger)
assert.Equal(t, "test-deployment", logger.Deployment)
assert.Equal(t, "test-namespace", logger.Namespace)
}
func TestTailer(t *testing.T) {
// Test tailer creation and methods
tailer := &Tailer{
lines: make(chan string),
done: make(chan struct{}),
}
// Test NextLine method
lineChan := tailer.NextLine()
assert.NotNil(t, lineChan)
// Test Stop method
tailer.Stop()
// Verify the done channel is closed
select {
case _, ok := <-tailer.done:
assert.False(t, ok, "done channel should be closed")
default:
assert.Fail(t, "done channel should be closed")
}
}
func TestTimeout(t *testing.T) {
// Test that timeout is handled correctly in Logger
logger := Logger{
Deployment: "test-deployment",
Namespace: "test-namespace",
Timeout: 100 * time.Millisecond,
}
assert.Equal(t, 100*time.Millisecond, logger.Timeout)
}