ooni-probe-cli/internal/cmd/oohelperd/logging_test.go
Simone Basso 4241ee4bc1
feat(oohelperd): log messages at info level (#896)
We're using a request-specific logger where we also print the ID
of the request. This design helps to observe logs produced by
concurrent requests.

Part of https://github.com/ooni/probe/issues/2183

While there, fix https://github.com/ooni/probe/issues/2241
2022-08-28 22:26:58 +02:00

106 lines
2.0 KiB
Go

package main
import (
"testing"
"github.com/ooni/probe-cli/v3/internal/model/mocks"
)
func TestIndexLogger(t *testing.T) {
t.Run("Debug", func(t *testing.T) {
expected := "<0>antani"
base := &mocks.Logger{
MockDebug: func(message string) {
if message != expected {
t.Fatal("unexpected message")
}
},
}
logger := &indexLogger{
indexstr: "<0>",
logger: base,
}
logger.Debug("antani")
})
t.Run("Info", func(t *testing.T) {
expected := "<0>antani"
base := &mocks.Logger{
MockInfo: func(message string) {
if message != expected {
t.Fatal("unexpected message")
}
},
}
logger := &indexLogger{
indexstr: "<0>",
logger: base,
}
logger.Info("antani")
})
t.Run("Warn", func(t *testing.T) {
expected := "<0>antani"
base := &mocks.Logger{
MockWarn: func(message string) {
if message != expected {
t.Fatal("unexpected message")
}
},
}
logger := &indexLogger{
indexstr: "<0>",
logger: base,
}
logger.Warn("antani")
})
t.Run("Debugf", func(t *testing.T) {
expected := "<0>antani%d"
base := &mocks.Logger{
MockDebugf: func(format string, v ...any) {
if format != expected {
t.Fatal("unexpected message")
}
},
}
logger := &indexLogger{
indexstr: "<0>",
logger: base,
}
logger.Debugf("antani%d", 11)
})
t.Run("Infof", func(t *testing.T) {
expected := "<0>antani%d"
base := &mocks.Logger{
MockInfof: func(format string, v ...any) {
if format != expected {
t.Fatal("unexpected message")
}
},
}
logger := &indexLogger{
indexstr: "<0>",
logger: base,
}
logger.Infof("antani%d", 11)
})
t.Run("Warnf", func(t *testing.T) {
expected := "<0>antani%d"
base := &mocks.Logger{
MockWarnf: func(format string, v ...any) {
if format != expected {
t.Fatal("unexpected message")
}
},
}
logger := &indexLogger{
indexstr: "<0>",
logger: base,
}
logger.Warnf("antani%d", 11)
})
}