mirror of
https://github.com/wneessen/go-mail.git
synced 2024-11-15 02:12:55 +01:00
Add tests for MsgWriter_writeString function
Implemented tests to validate the MsgWriter writeString method for successful writes, failure scenarios, and handling pre-existing errors in the writer. This improves coverage and ensures robustness of the MsgWriter component.
This commit is contained in:
parent
dedb0e36c8
commit
b7a87fb15b
1 changed files with 31 additions and 0 deletions
|
@ -468,3 +468,34 @@ func TestMsgWriter_writePart(t *testing.T) {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestMsgWriter_writeString(t *testing.T) {
|
||||||
|
msgwriter := &msgWriter{
|
||||||
|
charset: CharsetUTF8,
|
||||||
|
encoder: getEncoder(EncodingQP),
|
||||||
|
}
|
||||||
|
t.Run("writeString succeeds", func(t *testing.T) {
|
||||||
|
buffer := bytes.NewBuffer(nil)
|
||||||
|
msgwriter.writer = buffer
|
||||||
|
msgwriter.writeString("thisisatest")
|
||||||
|
if !strings.EqualFold(buffer.String(), "thisisatest") {
|
||||||
|
t.Errorf("writeString failed, expected: thisisatest got: %s", buffer.String())
|
||||||
|
}
|
||||||
|
})
|
||||||
|
t.Run("writeString fails", func(t *testing.T) {
|
||||||
|
msgwriter.writer = failReadWriteSeekCloser{}
|
||||||
|
msgwriter.writeString("thisisatest")
|
||||||
|
if msgwriter.err == nil {
|
||||||
|
t.Errorf("writeString succeeded, expected error")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
t.Run("writeString on errored writer should return", func(t *testing.T) {
|
||||||
|
buffer := bytes.NewBuffer(nil)
|
||||||
|
msgwriter.writer = buffer
|
||||||
|
msgwriter.err = errors.New("intentional error")
|
||||||
|
msgwriter.writeString("thisisatest")
|
||||||
|
if !strings.EqualFold(buffer.String(), "") {
|
||||||
|
t.Errorf("writeString succeeded, expected: empty string, got: %s", buffer.String())
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue