mirror of
https://github.com/wneessen/go-mail.git
synced 2024-11-25 07:00:49 +01:00
Compare commits
No commits in common. "9682755e25bb2267768b8901c7574fe7134f86d7" and "e808e0b972ef61d243282e70cc10e16dfe4399fd" have entirely different histories.
9682755e25
...
e808e0b972
11 changed files with 514 additions and 1794 deletions
23
.cirrus.yml
Normal file
23
.cirrus.yml
Normal file
|
@ -0,0 +1,23 @@
|
|||
# SPDX-FileCopyrightText: 2022 Winni Neessen <winni@neessen.dev>
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
freebsd_task:
|
||||
name: FreeBSD
|
||||
|
||||
matrix:
|
||||
- name: FreeBSD 13.3
|
||||
freebsd_instance:
|
||||
image_family: freebsd-13-3
|
||||
- name: FreeBSD 14.0
|
||||
freebsd_instance:
|
||||
image_family: freebsd-14-0
|
||||
|
||||
env:
|
||||
TEST_SKIP_SENDMAIL: 1
|
||||
|
||||
pkginstall_script:
|
||||
- pkg install -y go
|
||||
|
||||
test_script:
|
||||
- go test -race -cover -shuffle=on ./...
|
20
.github/workflows/ci.yml
vendored
20
.github/workflows/ci.yml
vendored
|
@ -136,26 +136,6 @@ jobs:
|
|||
- name: Run go test
|
||||
run: |
|
||||
go test -race -shuffle=on ./...
|
||||
test-fbsd:
|
||||
name: Test on FreeBSD ${{ matrix.osver }}
|
||||
runs-on: ubuntu-latest
|
||||
concurrency:
|
||||
group: ci-test-freebsd-${{ matrix.osver }}
|
||||
cancel-in-progress: true
|
||||
strategy:
|
||||
matrix:
|
||||
osver: ['13.4', '14.0', '14.1']
|
||||
steps:
|
||||
- name: Checkout Code
|
||||
uses: actions/checkout@61b9e3751b92087fd0b06925ba6dd6314e06f089 # master
|
||||
- name: Run go test on FreeBSD
|
||||
uses: vmactions/freebsd-vm@v1
|
||||
with:
|
||||
usesh: true
|
||||
prepare: |
|
||||
pkg install -y go
|
||||
run: |
|
||||
go test -race -shuffle=on ./...
|
||||
reuse:
|
||||
name: REUSE Compliance Check
|
||||
runs-on: ubuntu-latest
|
||||
|
|
|
@ -2579,10 +2579,6 @@ func TestClient_Send(t *testing.T) {
|
|||
}
|
||||
t.Cleanup(func() {
|
||||
if err := client.Close(); err != nil {
|
||||
var netErr net.Error
|
||||
if errors.As(err, &netErr) && netErr.Timeout() {
|
||||
t.Skip("failed to close the test server connection due to timeout")
|
||||
}
|
||||
t.Errorf("failed to close client: %s", err)
|
||||
}
|
||||
})
|
||||
|
|
24
msg.go
24
msg.go
|
@ -1681,11 +1681,11 @@ func (m *Msg) SetBodyHTMLTemplate(tpl *ht.Template, data interface{}, opts ...Pa
|
|||
if tpl == nil {
|
||||
return errors.New(errTplPointerNil)
|
||||
}
|
||||
buffer := bytes.NewBuffer(nil)
|
||||
if err := tpl.Execute(buffer, data); err != nil {
|
||||
buffer := bytes.Buffer{}
|
||||
if err := tpl.Execute(&buffer, data); err != nil {
|
||||
return fmt.Errorf(errTplExecuteFailed, err)
|
||||
}
|
||||
writeFunc := writeFuncFromBuffer(buffer)
|
||||
writeFunc := writeFuncFromBuffer(&buffer)
|
||||
m.SetBodyWriter(TypeTextHTML, writeFunc, opts...)
|
||||
return nil
|
||||
}
|
||||
|
@ -1712,11 +1712,11 @@ func (m *Msg) SetBodyTextTemplate(tpl *tt.Template, data interface{}, opts ...Pa
|
|||
if tpl == nil {
|
||||
return errors.New(errTplPointerNil)
|
||||
}
|
||||
buffer := bytes.NewBuffer(nil)
|
||||
if err := tpl.Execute(buffer, data); err != nil {
|
||||
buf := bytes.Buffer{}
|
||||
if err := tpl.Execute(&buf, data); err != nil {
|
||||
return fmt.Errorf(errTplExecuteFailed, err)
|
||||
}
|
||||
writeFunc := writeFuncFromBuffer(buffer)
|
||||
writeFunc := writeFuncFromBuffer(&buf)
|
||||
m.SetBodyWriter(TypeTextPlain, writeFunc, opts...)
|
||||
return nil
|
||||
}
|
||||
|
@ -1786,11 +1786,11 @@ func (m *Msg) AddAlternativeHTMLTemplate(tpl *ht.Template, data interface{}, opt
|
|||
if tpl == nil {
|
||||
return errors.New(errTplPointerNil)
|
||||
}
|
||||
buffer := bytes.NewBuffer(nil)
|
||||
if err := tpl.Execute(buffer, data); err != nil {
|
||||
buffer := bytes.Buffer{}
|
||||
if err := tpl.Execute(&buffer, data); err != nil {
|
||||
return fmt.Errorf(errTplExecuteFailed, err)
|
||||
}
|
||||
writeFunc := writeFuncFromBuffer(buffer)
|
||||
writeFunc := writeFuncFromBuffer(&buffer)
|
||||
m.AddAlternativeWriter(TypeTextHTML, writeFunc, opts...)
|
||||
return nil
|
||||
}
|
||||
|
@ -1816,11 +1816,11 @@ func (m *Msg) AddAlternativeTextTemplate(tpl *tt.Template, data interface{}, opt
|
|||
if tpl == nil {
|
||||
return errors.New(errTplPointerNil)
|
||||
}
|
||||
buffer := bytes.NewBuffer(nil)
|
||||
if err := tpl.Execute(buffer, data); err != nil {
|
||||
buffer := bytes.Buffer{}
|
||||
if err := tpl.Execute(&buffer, data); err != nil {
|
||||
return fmt.Errorf(errTplExecuteFailed, err)
|
||||
}
|
||||
writeFunc := writeFuncFromBuffer(buffer)
|
||||
writeFunc := writeFuncFromBuffer(&buffer)
|
||||
m.AddAlternativeWriter(TypeTextPlain, writeFunc, opts...)
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -8,126 +8,12 @@
|
|||
package mail
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestMsg_AttachFile_unixOnly(t *testing.T) {
|
||||
t.Run("AttachFile with fileFromFS fails on open", func(t *testing.T) {
|
||||
tempfile, err := os.CreateTemp("testdata/tmp", "attachfile-unable-to-open.*.txt")
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create temp file: %s", err)
|
||||
}
|
||||
t.Cleanup(func() {
|
||||
if err := os.Remove(tempfile.Name()); err != nil {
|
||||
t.Errorf("failed to remove temp file: %s", err)
|
||||
}
|
||||
})
|
||||
if err = os.Chmod(tempfile.Name(), 0o000); err != nil {
|
||||
t.Fatalf("failed to chmod temp file to 0000: %s", err)
|
||||
}
|
||||
message := NewMsg()
|
||||
if message == nil {
|
||||
t.Fatal("message is nil")
|
||||
}
|
||||
message.AttachFile(tempfile.Name())
|
||||
attachments := message.GetAttachments()
|
||||
if len(attachments) != 1 {
|
||||
t.Fatalf("failed to get attachments, expected 1, got: %d", len(attachments))
|
||||
}
|
||||
messageBuf := bytes.NewBuffer(nil)
|
||||
_, err = attachments[0].Writer(messageBuf)
|
||||
if err == nil {
|
||||
t.Error("writer func expected to fail, but didn't")
|
||||
}
|
||||
if !errors.Is(err, os.ErrPermission) {
|
||||
t.Errorf("expected error to be %s, got: %s", os.ErrPermission, err)
|
||||
}
|
||||
})
|
||||
t.Run("AttachFile with fileFromFS fails on copy", func(t *testing.T) {
|
||||
tempfile, err := os.CreateTemp("testdata/tmp", "attachfile-close-early.*.txt")
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create temp file: %s", err)
|
||||
}
|
||||
t.Cleanup(func() {
|
||||
if err := os.Remove(tempfile.Name()); err != nil {
|
||||
t.Errorf("failed to remove temp file: %s", err)
|
||||
}
|
||||
})
|
||||
message := NewMsg()
|
||||
if message == nil {
|
||||
t.Fatal("message is nil")
|
||||
}
|
||||
message.AttachFile("testdata/attachment.txt")
|
||||
attachments := message.GetAttachments()
|
||||
if len(attachments) != 1 {
|
||||
t.Fatalf("failed to get attachments, expected 1, got: %d", len(attachments))
|
||||
}
|
||||
messageBuf, err := os.Open(tempfile.Name())
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open temp file: %s", err)
|
||||
}
|
||||
// We close early to cause an error during io.Copy
|
||||
if err = messageBuf.Close(); err != nil {
|
||||
t.Fatalf("failed to close temp file: %s", err)
|
||||
}
|
||||
_, err = attachments[0].Writer(messageBuf)
|
||||
if err == nil {
|
||||
t.Error("writer func expected to fail, but didn't")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestMsg_AttachReader_unixOnly(t *testing.T) {
|
||||
t.Run("AttachReader with fileFromReader fails on copy", func(t *testing.T) {
|
||||
tempfile, err := os.CreateTemp("", "attachfile-close-early.*.txt")
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create temp file: %s", err)
|
||||
}
|
||||
t.Cleanup(func() {
|
||||
if err := os.Remove(tempfile.Name()); err != nil {
|
||||
t.Errorf("failed to remove temp file: %s", err)
|
||||
}
|
||||
})
|
||||
message := NewMsg()
|
||||
if message == nil {
|
||||
t.Fatal("message is nil")
|
||||
}
|
||||
file, err := os.Open("testdata/attachment.txt")
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open file: %s", err)
|
||||
}
|
||||
t.Cleanup(func() {
|
||||
if err := file.Close(); err != nil {
|
||||
t.Errorf("failed to close file: %s", err)
|
||||
}
|
||||
})
|
||||
if err = message.AttachReader("attachment.txt", file); err != nil {
|
||||
t.Fatalf("failed to attach reader: %s", err)
|
||||
}
|
||||
attachments := message.GetAttachments()
|
||||
if len(attachments) != 1 {
|
||||
t.Fatalf("failed to get attachments, expected 1, got: %d", len(attachments))
|
||||
}
|
||||
messageBuf, err := os.Open(tempfile.Name())
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open temp file: %s", err)
|
||||
}
|
||||
// We close early to cause an error during io.Copy
|
||||
if err = messageBuf.Close(); err != nil {
|
||||
t.Fatalf("failed to close temp file: %s", err)
|
||||
}
|
||||
_, err = attachments[0].Writer(messageBuf)
|
||||
if err == nil {
|
||||
t.Error("writer func expected to fail, but didn't")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// TestMsg_WriteToSendmailWithContext tests the WriteToSendmailWithContext() method of the Msg
|
||||
func TestMsg_WriteToSendmailWithContext(t *testing.T) {
|
||||
if os.Getenv("TEST_SENDMAIL") != "true" {
|
||||
|
|
2115
msg_test.go
2115
msg_test.go
File diff suppressed because it is too large
Load diff
1
testdata/attachment.txt
vendored
1
testdata/attachment.txt
vendored
|
@ -1 +0,0 @@
|
|||
This is a test attachment
|
3
testdata/attachment.txt.license
vendored
3
testdata/attachment.txt.license
vendored
|
@ -1,3 +0,0 @@
|
|||
// SPDX-FileCopyrightText: Copyright (c) 2022-2024 The go-mail Authors
|
||||
//
|
||||
// SPDX-License-Identifier: MIT
|
1
testdata/embed.txt
vendored
1
testdata/embed.txt
vendored
|
@ -1 +0,0 @@
|
|||
This is a test embed
|
3
testdata/embed.txt.license
vendored
3
testdata/embed.txt.license
vendored
|
@ -1,3 +0,0 @@
|
|||
// SPDX-FileCopyrightText: Copyright (c) 2022-2024 The go-mail Authors
|
||||
//
|
||||
// SPDX-License-Identifier: MIT
|
0
testdata/tmp/.gitkeep
vendored
0
testdata/tmp/.gitkeep
vendored
Loading…
Reference in a new issue