aboutsummaryrefslogtreecommitdiffstats
path: root/lib/rfc822/message_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rfc822/message_test.go')
-rw-r--r--lib/rfc822/message_test.go84
1 files changed, 84 insertions, 0 deletions
diff --git a/lib/rfc822/message_test.go b/lib/rfc822/message_test.go
new file mode 100644
index 00000000..8730afe2
--- /dev/null
+++ b/lib/rfc822/message_test.go
@@ -0,0 +1,84 @@
+package rfc822_test
+
+import (
+ "io"
+ "os"
+ "path/filepath"
+ "testing"
+
+ "git.sr.ht/~rjarry/aerc/lib/rfc822"
+ "git.sr.ht/~rjarry/aerc/models"
+)
+
+func TestMessageInfoParser(t *testing.T) {
+ rootDir := "testdata/message/valid"
+ msgFiles, err := os.ReadDir(rootDir)
+ die(err)
+
+ for _, fi := range msgFiles {
+ if fi.IsDir() {
+ continue
+ }
+
+ p := fi.Name()
+ t.Run(p, func(t *testing.T) {
+ m := newMockRawMessageFromPath(filepath.Join(rootDir, p))
+ mi, err := rfc822.MessageInfo(m)
+ if err != nil {
+ t.Fatal("Failed to create MessageInfo with:", err)
+ }
+
+ if perr := mi.Error; perr != nil {
+ t.Fatal("Expected no parsing error, but got:", mi.Error)
+ }
+ })
+ }
+}
+
+func TestMessageInfoHandledError(t *testing.T) {
+ rootDir := "testdata/message/invalid"
+ msgFiles, err := os.ReadDir(rootDir)
+ die(err)
+
+ for _, fi := range msgFiles {
+ if fi.IsDir() {
+ continue
+ }
+
+ p := fi.Name()
+ t.Run(p, func(t *testing.T) {
+ m := newMockRawMessageFromPath(filepath.Join(rootDir, p))
+ mi, err := rfc822.MessageInfo(m)
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ if perr := mi.Error; perr == nil {
+ t.Fatal("Expected MessageInfo.Error, got none")
+ }
+ })
+ }
+}
+
+type mockRawMessage struct {
+ path string
+}
+
+func newMockRawMessageFromPath(p string) *mockRawMessage {
+ return &mockRawMessage{
+ path: p,
+ }
+}
+
+func (m *mockRawMessage) NewReader() (io.ReadCloser, error) {
+ return os.Open(m.path)
+}
+func (m *mockRawMessage) ModelFlags() (models.Flags, error) { return 0, nil }
+func (m *mockRawMessage) Labels() ([]string, error) { return nil, nil }
+func (m *mockRawMessage) UID() uint32 { return 0 }
+
+func die(err error) {
+ if err != nil {
+ panic(err)
+ }
+}