aboutsummaryrefslogtreecommitdiffstats
path: root/worker/lib/parse_test.go
diff options
context:
space:
mode:
authorNguyễn Gia Phong <mcsinyx@disroot.org>2022-01-20 01:10:08 +0700
committerRobin Jarry <robin@jarry.cc>2022-01-19 20:18:00 +0100
commit904ffacb0e521218ba1f41e2e5c26d9ac41c9969 (patch)
tree4bb0dbe000b1241586f7fb0635ee076f70c22fe2 /worker/lib/parse_test.go
parentbeae17a6da37402d1c69dc76b476f55cbae982b8 (diff)
downloadaerc-904ffacb0e521218ba1f41e2e5c26d9ac41c9969.tar.gz
maildir,notmuch: avoid leaking open files
Previously, Message.NewReader returned the wrapped buffered reader without a reference to the opened file, so the files descriptors were left unclosed after reading. Now, the file reader is returned directly and closed on the call site. Buffering is not needed here because it is an implementation detail of go-message. Fixes: https://todo.sr.ht/~rjarry/aerc/9
Diffstat (limited to 'worker/lib/parse_test.go')
-rw-r--r--worker/lib/parse_test.go18
1 files changed, 6 insertions, 12 deletions
diff --git a/worker/lib/parse_test.go b/worker/lib/parse_test.go
index 5c0a1b17..12190981 100644
--- a/worker/lib/parse_test.go
+++ b/worker/lib/parse_test.go
@@ -1,9 +1,9 @@
package lib
import (
- "bytes"
"io"
"io/ioutil"
+ "os"
"path/filepath"
"testing"
@@ -36,23 +36,17 @@ func TestMessageInfoHandledError(t *testing.T) {
}
type mockRawMessage struct {
- body []byte
+ path string
}
-func newMockRawMessage(body []byte) *mockRawMessage {
+func newMockRawMessageFromPath(p string) *mockRawMessage {
return &mockRawMessage{
- body: body,
+ path: p,
}
}
-func newMockRawMessageFromPath(p string) *mockRawMessage {
- b, err := ioutil.ReadFile(p)
- die(err)
- return newMockRawMessage(b)
-}
-
-func (m *mockRawMessage) NewReader() (io.Reader, error) {
- return bytes.NewReader(m.body), nil
+func (m *mockRawMessage) NewReader() (io.ReadCloser, error) {
+ return os.Open(m.path)
}
func (m *mockRawMessage) ModelFlags() ([]models.Flag, error) { return nil, nil }
func (m *mockRawMessage) Labels() ([]string, error) { return nil, nil }