mirror of
https://github.com/wneessen/go-mail.git
synced 2024-12-22 18:50:37 +01:00
Add tests for Client debug logging behavior
Introduce unit tests to verify the behavior of the debug logging in the Client. Confirm that logs are correctly produced when debug mode is enabled and appropriately suppressed when it is disabled.
This commit is contained in:
parent
3b9085e19d
commit
c58aa35454
1 changed files with 28 additions and 0 deletions
|
@ -3512,6 +3512,34 @@ func TestClient_GetTLSConnectionState(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func TestClient_debugLog(t *testing.T) {
|
||||
t.Run("debug log is enabled", func(t *testing.T) {
|
||||
buffer := bytes.NewBuffer(nil)
|
||||
logger := log.New(buffer, log.LevelDebug)
|
||||
client := &Client{logger: logger, debug: true}
|
||||
client.debugLog(log.DirClientToServer, "%s", "simple string")
|
||||
client.debugLog(log.DirServerToClient, "%d", 1234)
|
||||
want := "DEBUG: C --> S: simple string"
|
||||
if !strings.Contains(buffer.String(), want) {
|
||||
t.Errorf("expected debug log to contain %q, got: %q", want, buffer.String())
|
||||
}
|
||||
want = "DEBUG: C <-- S: 1234"
|
||||
if !strings.Contains(buffer.String(), want) {
|
||||
t.Errorf("expected debug log to contain %q, got: %q", want, buffer.String())
|
||||
}
|
||||
})
|
||||
t.Run("debug log is disable", func(t *testing.T) {
|
||||
buffer := bytes.NewBuffer(nil)
|
||||
logger := log.New(buffer, log.LevelDebug)
|
||||
client := &Client{logger: logger, debug: false}
|
||||
client.debugLog(log.DirClientToServer, "%s", "simple string")
|
||||
client.debugLog(log.DirServerToClient, "%d", 1234)
|
||||
if buffer.Len() > 0 {
|
||||
t.Errorf("expected debug log to be empty, got: %q", buffer.String())
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 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