2020-08-21 20:58:30 +02:00
|
|
|
package lib
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
"io/ioutil"
|
2022-01-19 19:10:08 +01:00
|
|
|
"os"
|
2020-08-21 20:58:30 +02:00
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
|
|
|
|
2021-11-05 10:19:46 +01:00
|
|
|
"git.sr.ht/~rjarry/aerc/models"
|
2020-08-21 20:58:30 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestMessageInfoHandledError(t *testing.T) {
|
|
|
|
rootDir := "testdata/message/invalid"
|
|
|
|
msgFiles, err := ioutil.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 := MessageInfo(m)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if perr := mi.Error; perr == nil {
|
|
|
|
t.Fatal("Expected MessageInfo.Error, got none")
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type mockRawMessage struct {
|
2022-01-19 19:10:08 +01:00
|
|
|
path string
|
2020-08-21 20:58:30 +02:00
|
|
|
}
|
|
|
|
|
2022-01-19 19:10:08 +01:00
|
|
|
func newMockRawMessageFromPath(p string) *mockRawMessage {
|
2020-08-21 20:58:30 +02:00
|
|
|
return &mockRawMessage{
|
2022-01-19 19:10:08 +01:00
|
|
|
path: p,
|
2020-08-21 20:58:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-19 19:10:08 +01:00
|
|
|
func (m *mockRawMessage) NewReader() (io.ReadCloser, error) {
|
|
|
|
return os.Open(m.path)
|
2020-08-21 20:58:30 +02:00
|
|
|
}
|
|
|
|
func (m *mockRawMessage) ModelFlags() ([]models.Flag, error) { return nil, 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)
|
|
|
|
}
|
|
|
|
}
|