mirror of
https://github.com/wneessen/go-mail.git
synced 2024-12-22 18:50:37 +01:00
Add tests for Client's SetLogger method
This commit introduces unit tests for the Client's SetLogger method. It verifies the correct logger type is set and ensures setting a nil logger does not override an existing logger.
This commit is contained in:
parent
9412f31874
commit
5e3d14f842
1 changed files with 24 additions and 0 deletions
|
@ -3169,6 +3169,30 @@ func TestClient_SetDebugLog(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func TestClient_SetLogger(t *testing.T) {
|
||||
t.Run("set logger to Stdlog logger", func(t *testing.T) {
|
||||
client := &Client{}
|
||||
client.SetLogger(log.New(os.Stderr, log.LevelDebug))
|
||||
if !strings.EqualFold(fmt.Sprintf("%T", client.logger), "*log.Stdlog") {
|
||||
t.Errorf("expected logger to be of type *log.Stdlog, got: %T", client.logger)
|
||||
}
|
||||
})
|
||||
t.Run("set logger to JSONlog logger", func(t *testing.T) {
|
||||
client := &Client{}
|
||||
client.SetLogger(log.NewJSON(os.Stderr, log.LevelDebug))
|
||||
if !strings.EqualFold(fmt.Sprintf("%T", client.logger), "*log.JSONlog") {
|
||||
t.Errorf("expected logger to be of type *log.JSONlog, got: %T", client.logger)
|
||||
}
|
||||
})
|
||||
t.Run("nil logger should just return and not set/override", func(t *testing.T) {
|
||||
client := &Client{logger: log.NewJSON(os.Stderr, log.LevelDebug)}
|
||||
client.SetLogger(nil)
|
||||
if !strings.EqualFold(fmt.Sprintf("%T", client.logger), "*log.JSONlog") {
|
||||
t.Errorf("expected logger to be of type *log.JSONlog, got: %T", client.logger)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// faker is a struct embedding io.ReadWriter to simulate network connections for testing purposes.
|
||||
type faker struct {
|
||||
io.ReadWriter
|
||||
|
|
Loading…
Reference in a new issue