forked from Silverfish/proton-bridge
GODT-35: Finish all details and make tests pass
This commit is contained in:
@ -97,7 +97,7 @@ func fetchWorker(fetchReqCh <-chan fetchReq, fetchResCh chan<- fetchRes, attachW
|
||||
}
|
||||
|
||||
func fetchMessage(req fetchReq, attachWorkers int) (*pmapi.Message, [][]byte, error) {
|
||||
msg, err := req.api.GetMessage(req.messageID)
|
||||
msg, err := req.api.GetMessage(req.ctx, req.messageID)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
@ -109,7 +109,7 @@ func fetchMessage(req fetchReq, attachWorkers int) (*pmapi.Message, [][]byte, er
|
||||
}
|
||||
|
||||
process := func(value interface{}) (interface{}, error) {
|
||||
rc, err := req.api.GetAttachment(value.(string))
|
||||
rc, err := req.api.GetAttachment(req.ctx, value.(string))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -43,10 +43,10 @@ func newTestFetcher(
|
||||
) Fetcher {
|
||||
f := mocks.NewMockFetcher(m)
|
||||
|
||||
f.EXPECT().GetMessage(msg.ID).Return(msg, nil)
|
||||
f.EXPECT().GetMessage(gomock.Any(), msg.ID).Return(msg, nil)
|
||||
|
||||
for i, att := range msg.Attachments {
|
||||
f.EXPECT().GetAttachment(att.ID).Return(newTestReadCloser(attData[i]), nil)
|
||||
f.EXPECT().GetAttachment(gomock.Any(), att.ID).Return(newTestReadCloser(attData[i]), nil)
|
||||
}
|
||||
|
||||
f.EXPECT().KeyRingForAddressID(msg.AddressID).Return(kr, nil)
|
||||
|
||||
@ -1230,7 +1230,7 @@ func TestBuildFetchMessageFail(t *testing.T) {
|
||||
|
||||
// Pretend the message cannot be fetched.
|
||||
f := mocks.NewMockFetcher(m)
|
||||
f.EXPECT().GetMessage(msg.ID).Return(nil, errors.New("oops"))
|
||||
f.EXPECT().GetMessage(gomock.Any(), msg.ID).Return(nil, errors.New("oops"))
|
||||
|
||||
// The job should fail, returning an error and a nil result.
|
||||
res, err := b.NewJob(context.Background(), f, msg.ID).GetResult()
|
||||
@ -1251,8 +1251,8 @@ func TestBuildFetchAttachmentFail(t *testing.T) {
|
||||
|
||||
// Pretend the attachment cannot be fetched.
|
||||
f := mocks.NewMockFetcher(m)
|
||||
f.EXPECT().GetMessage(msg.ID).Return(msg, nil)
|
||||
f.EXPECT().GetAttachment(msg.Attachments[0].ID).Return(nil, errors.New("oops"))
|
||||
f.EXPECT().GetMessage(gomock.Any(), msg.ID).Return(msg, nil)
|
||||
f.EXPECT().GetAttachment(gomock.Any(), msg.Attachments[0].ID).Return(nil, errors.New("oops"))
|
||||
|
||||
// The job should fail, returning an error and a nil result.
|
||||
res, err := b.NewJob(context.Background(), f, msg.ID).GetResult()
|
||||
@ -1272,7 +1272,7 @@ func TestBuildNoSuchKeyRing(t *testing.T) {
|
||||
|
||||
// Pretend there is no available keyring.
|
||||
f := mocks.NewMockFetcher(m)
|
||||
f.EXPECT().GetMessage(msg.ID).Return(msg, nil)
|
||||
f.EXPECT().GetMessage(gomock.Any(), msg.ID).Return(msg, nil)
|
||||
f.EXPECT().KeyRingForAddressID(msg.AddressID).Return(nil, errors.New("oops"))
|
||||
|
||||
res, err := b.NewJob(context.Background(), f, msg.ID).GetResult()
|
||||
|
||||
@ -31,7 +31,7 @@ const (
|
||||
|
||||
// GetFlags returns imap flags from pmapi message attributes.
|
||||
func GetFlags(m *pmapi.Message) (flags []string) {
|
||||
if m.Unread == 0 {
|
||||
if !m.Unread {
|
||||
flags = append(flags, imap.SeenFlag)
|
||||
}
|
||||
if !m.Has(pmapi.FlagSent) && !m.Has(pmapi.FlagReceived) {
|
||||
@ -68,11 +68,11 @@ func ParseFlags(m *pmapi.Message, flags []string) {
|
||||
m.Flags = pmapi.FlagReceived
|
||||
}
|
||||
|
||||
m.Unread = 1
|
||||
m.Unread = true
|
||||
for _, f := range flags {
|
||||
switch f {
|
||||
case imap.SeenFlag:
|
||||
m.Unread = 0
|
||||
m.Unread = false
|
||||
case imap.DraftFlag:
|
||||
m.Flags &= ^pmapi.FlagSent
|
||||
m.Flags &= ^pmapi.FlagReceived
|
||||
|
||||
@ -5,6 +5,7 @@
|
||||
package mocks
|
||||
|
||||
import (
|
||||
context "context"
|
||||
io "io"
|
||||
reflect "reflect"
|
||||
|
||||
@ -37,33 +38,33 @@ func (m *MockFetcher) EXPECT() *MockFetcherMockRecorder {
|
||||
}
|
||||
|
||||
// GetAttachment mocks base method
|
||||
func (m *MockFetcher) GetAttachment(arg0 string) (io.ReadCloser, error) {
|
||||
func (m *MockFetcher) GetAttachment(arg0 context.Context, arg1 string) (io.ReadCloser, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetAttachment", arg0)
|
||||
ret := m.ctrl.Call(m, "GetAttachment", arg0, arg1)
|
||||
ret0, _ := ret[0].(io.ReadCloser)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// GetAttachment indicates an expected call of GetAttachment
|
||||
func (mr *MockFetcherMockRecorder) GetAttachment(arg0 interface{}) *gomock.Call {
|
||||
func (mr *MockFetcherMockRecorder) GetAttachment(arg0, arg1 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAttachment", reflect.TypeOf((*MockFetcher)(nil).GetAttachment), arg0)
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAttachment", reflect.TypeOf((*MockFetcher)(nil).GetAttachment), arg0, arg1)
|
||||
}
|
||||
|
||||
// GetMessage mocks base method
|
||||
func (m *MockFetcher) GetMessage(arg0 string) (*pmapi.Message, error) {
|
||||
func (m *MockFetcher) GetMessage(arg0 context.Context, arg1 string) (*pmapi.Message, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetMessage", arg0)
|
||||
ret := m.ctrl.Call(m, "GetMessage", arg0, arg1)
|
||||
ret0, _ := ret[0].(*pmapi.Message)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// GetMessage indicates an expected call of GetMessage
|
||||
func (mr *MockFetcherMockRecorder) GetMessage(arg0 interface{}) *gomock.Call {
|
||||
func (mr *MockFetcherMockRecorder) GetMessage(arg0, arg1 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetMessage", reflect.TypeOf((*MockFetcher)(nil).GetMessage), arg0)
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetMessage", reflect.TypeOf((*MockFetcher)(nil).GetMessage), arg0, arg1)
|
||||
}
|
||||
|
||||
// KeyRingForAddressID mocks base method
|
||||
|
||||
Reference in New Issue
Block a user