Added test capability and tests for authentication middleware

This commit is contained in:
2025-02-12 21:23:13 +11:00
parent ca92d573ba
commit 2d52084fa7
12 changed files with 334 additions and 9 deletions

29
tests/logger.go Normal file
View File

@@ -0,0 +1,29 @@
package tests
import (
"testing"
"github.com/rs/zerolog"
)
type TLogWriter struct {
t *testing.T
}
// Write implements the io.Writer interface for TLogWriter.
func (w *TLogWriter) Write(p []byte) (n int, err error) {
w.t.Logf("%s", p)
return len(p), nil
}
// Return a fake logger to satisfy functions that expect one
func NilLogger() *zerolog.Logger {
logger := zerolog.New(nil)
return &logger
}
// Return a logger that makes use of the T.Log method to enable debugging tests
func DebugLogger(t *testing.T) *zerolog.Logger {
logger := zerolog.New(&TLogWriter{t: t})
return &logger
}