mirror of
https://github.com/wneessen/go-mail.git
synced 2024-11-15 02:12:55 +01:00
Add test for Client cmd failure on textproto command
This commit introduces a new test case for the `Client`'s `cmd` method to ensure it fails correctly when the `textproto` command encounters a broken writer. It also adds a `failWriter` struct that simulates a write failure to facilitate this testing scenario.
This commit is contained in:
parent
af7964450a
commit
50505e1339
1 changed files with 30 additions and 0 deletions
|
@ -1668,6 +1668,29 @@ func TestClient_Hello(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func TestClient_cmd(t *testing.T) {
|
||||
t.Run("cmd fails on textproto cmd", func(t *testing.T) {
|
||||
server := "220 server ready\r\n"
|
||||
var fake faker
|
||||
fake.failOnClose = true
|
||||
fake.ReadWriter = struct {
|
||||
io.Reader
|
||||
io.Writer
|
||||
}{
|
||||
strings.NewReader(server),
|
||||
&failWriter{},
|
||||
}
|
||||
client, err := NewClient(fake, "faker.host")
|
||||
if err != nil {
|
||||
t.Errorf("failed to create client: %s", err)
|
||||
}
|
||||
_, _, err = client.cmd(250, "HELO faker.host")
|
||||
if err == nil {
|
||||
t.Error("cmd should fail on textproto cmd with broken writer")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Issue 17794: don't send a trailing space on AUTH command when there's no password.
|
||||
func TestClient_Auth_trimSpace(t *testing.T) {
|
||||
server := "220 hello world\r\n" +
|
||||
|
@ -3656,3 +3679,10 @@ func (toServerEmptyAuth) Start(_ *ServerInfo) (proto string, toServer []byte, er
|
|||
func (toServerEmptyAuth) Next(_ []byte, _ bool) (toServer []byte, err error) {
|
||||
return nil, fmt.Errorf("unexpected call")
|
||||
}
|
||||
|
||||
// failWriter is a struct type that implements the io.Writer interface, but always returns an error on Write.
|
||||
type failWriter struct{}
|
||||
|
||||
func (w *failWriter) Write([]byte) (int, error) {
|
||||
return 0, errors.New("broken writer")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue