test(config,git,logger): add some test functions
This commit is contained in:
parent
316e5de757
commit
1356128a7b
16 changed files with 387 additions and 25 deletions
49
internal/logger/logger_test.go
Normal file
49
internal/logger/logger_test.go
Normal file
|
@ -0,0 +1,49 @@
|
|||
package logger_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
|
||||
"git.ar21.de/yolokube/grafana-backuper/internal/logger"
|
||||
"github.com/rs/zerolog"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestCliLoggerLayout_DebugLevel(t *testing.T) {
|
||||
var buf bytes.Buffer
|
||||
zerolog.SetGlobalLevel(zerolog.DebugLevel)
|
||||
|
||||
log := logger.CliLoggerLayout(&buf)
|
||||
log.Debug().Msg("test message")
|
||||
|
||||
output := buf.String()
|
||||
assert.Contains(t, output, "test message")
|
||||
assert.Contains(t, output, "DBG") // Assuming zerolog adds a short level indicator like "DBG"
|
||||
assert.Contains(t, output, ".go:") // Ensures the caller file and line are included
|
||||
}
|
||||
|
||||
func TestCliLoggerLayout_NonDebugLevel(t *testing.T) {
|
||||
var buf bytes.Buffer
|
||||
zerolog.SetGlobalLevel(zerolog.InfoLevel)
|
||||
|
||||
log := logger.CliLoggerLayout(&buf)
|
||||
log.Info().Msg("test message")
|
||||
|
||||
output := buf.String()
|
||||
assert.Contains(t, output, "test message")
|
||||
assert.NotContains(t, output, "DBG") // Since we're at Info level
|
||||
assert.NotContains(t, output, ".go:") // Caller information should not be included
|
||||
}
|
||||
|
||||
func TestJSONLoggerLayout(t *testing.T) {
|
||||
var buf bytes.Buffer
|
||||
|
||||
log := logger.JSONLoggerLayout(&buf)
|
||||
log.Info().Msg("test message")
|
||||
|
||||
output := buf.String()
|
||||
assert.Contains(t, output, `"message":"test message"`)
|
||||
assert.Contains(t, output, `"level":"info"`)
|
||||
assert.Contains(t, output, `"time":`) // Timestamp should be included
|
||||
assert.Contains(t, output, `"caller":`) // Caller should be included
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue