aboutsummaryrefslogtreecommitdiffstats
path: root/lib/rfc822/message_test.go
diff options
context:
space:
mode:
authorRobin Jarry <robin@jarry.cc>2023-10-17 14:40:08 +0200
committerRobin Jarry <robin@jarry.cc>2023-10-28 19:24:55 +0200
commit57088312fdd8e602a084bd5736a0e22a34be9ec0 (patch)
tree8c5544262cf8c1772ec661748cfa4d5491ff4c77 /lib/rfc822/message_test.go
parent591659b52867cb118d1f82d41693a02123935e0c (diff)
downloadaerc-57088312fdd8e602a084bd5736a0e22a34be9ec0.tar.gz
worker: move shared code to lib
Avoid importing code from worker/lib into lib. It should only be the other way around. Move the message parsing code used by maildir, notmuch, mbox and the eml viewer into a lib/rfc822 package. Adapt imports accordingly. Signed-off-by: Robin Jarry <robin@jarry.cc> Reviewed-by: Koni Marti <koni.marti@gmail.com> Tested-by: Moritz Poldrack <moritz@poldrack.dev> Tested-by: Inwit <inwit@sindominio.net>
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)
+ }
+}