Fixes after rebase

This commit is contained in:
Michal Horejsek
2020-09-08 16:18:01 +02:00
parent 5496a26f73
commit d6464c0048
5 changed files with 47 additions and 13 deletions

View File

@ -103,7 +103,7 @@ func apiMailboxForAddressOfUserHasMessages(mailboxName, bddAddressID, bddUserID
head := messages.Rows[0].Cells head := messages.Rows[0].Cells
for _, row := range messages.Rows[1:] { for _, row := range messages.Rows[1:] {
found, err := messagesContainsMessageRow(account, pmapiMessages, head, row) found, err := pmapiMessagesContainsMessageRow(account, pmapiMessages, head, row)
if err != nil { if err != nil {
return err return err
} }

View File

@ -161,3 +161,4 @@ func (ctl *Controller) GetMessages(username, labelID string) ([]*pmapi.Message,
} }
return messages, nil return messages, nil
}

View File

@ -37,7 +37,7 @@ type IMAPResponse struct {
done bool done bool
} }
func (ir *IMAPResponse) sendCommand(reqTag string, reqIndex int, command string, debug *debug, conn io.Writer, response *bufio.Reader) { func (ir *IMAPResponse) sendCommand(reqTag string, reqIndex int, command string, debug *debug, conn io.Writer, response *bufio.Reader) { //nolint[interfacer]
defer func() { ir.done = true }() defer func() { ir.done = true }()
tstart := time.Now() tstart := time.Now()

View File

@ -24,6 +24,7 @@ import (
"time" "time"
"github.com/ProtonMail/proton-bridge/internal/store" "github.com/ProtonMail/proton-bridge/internal/store"
"github.com/ProtonMail/proton-bridge/pkg/pmapi"
"github.com/ProtonMail/proton-bridge/test/accounts" "github.com/ProtonMail/proton-bridge/test/accounts"
"github.com/cucumber/godog" "github.com/cucumber/godog"
"github.com/cucumber/godog/gherkin" "github.com/cucumber/godog/gherkin"
@ -143,7 +144,7 @@ func mailboxForAddressOfUserHasMessages(mailboxName, bddAddressID, bddUserID str
afterLimit := time.Since(start) > ctx.EventLoopTimeout() afterLimit := time.Since(start) > ctx.EventLoopTimeout()
allFound := true allFound := true
for _, row := range messages.Rows[1:] { for _, row := range messages.Rows[1:] {
found, err := messagesContainsMessageRow(account, allMessages, head, row) found, err := storeMessagesContainsMessageRow(account, allMessages, head, row)
if err != nil { if err != nil {
return err return err
} }
@ -168,10 +169,36 @@ func mailboxForAddressOfUserHasMessages(mailboxName, bddAddressID, bddUserID str
return nil return nil
} }
func messagesContainsMessageRow(account *accounts.TestAccount, allMessages []*store.Message, head []*gherkin.TableCell, row *gherkin.TableRow) (bool, error) { //nolint[funlen] func pmapiMessagesContainsMessageRow(account *accounts.TestAccount, pmapiMessages []*pmapi.Message, head []*gherkin.TableCell, row *gherkin.TableRow) (bool, error) {
messages := make([]interface{}, len(pmapiMessages))
for i := range pmapiMessages {
messages[i] = pmapiMessages[i]
}
return messagesContainsMessageRow(account, messages, head, row)
}
func storeMessagesContainsMessageRow(account *accounts.TestAccount, storeMessages []*store.Message, head []*gherkin.TableCell, row *gherkin.TableRow) (bool, error) {
messages := make([]interface{}, len(storeMessages))
for i := range storeMessages {
messages[i] = storeMessages[i]
}
return messagesContainsMessageRow(account, messages, head, row)
}
func messagesContainsMessageRow(account *accounts.TestAccount, allMessages []interface{}, head []*gherkin.TableCell, row *gherkin.TableRow) (bool, error) { //nolint[funlen]
found := false found := false
for _, storeMessage := range allMessages { for _, someMessage := range allMessages {
message := storeMessage.Message() var message *pmapi.Message
var storeMessage *store.Message
switch v := someMessage.(type) {
case *pmapi.Message:
message = v
case *store.Message:
message = v.Message()
storeMessage = v
}
matches := true matches := true
for n, cell := range row.Cells { for n, cell := range row.Cells {
switch head[n].Value { switch head[n].Value {
@ -221,6 +248,10 @@ func messagesContainsMessageRow(account *accounts.TestAccount, allMessages []*st
matches = false matches = false
} }
case "deleted": case "deleted":
if storeMessage == nil {
return false, fmt.Errorf("deleted column not supported for pmapi message object")
}
expectedDeleted := cell.Value == "true" expectedDeleted := cell.Value == "true"
matches = storeMessage.IsMarkedDeleted() == expectedDeleted matches = storeMessage.IsMarkedDeleted() == expectedDeleted
default: default:

View File

@ -157,6 +157,7 @@ func thereAreMessagesInMailboxesForAddressOfUser(mailboxNames, bddAddressID, bdd
return err return err
} }
if len(markMessageIDsDeleted) > 0 {
for _, mailboxName := range strings.Split(mailboxNames, ",") { for _, mailboxName := range strings.Split(mailboxNames, ",") {
storeMailbox, err := ctx.GetStoreMailbox(account.Username(), account.AddressID(), mailboxName) storeMailbox, err := ctx.GetStoreMailbox(account.Username(), account.AddressID(), mailboxName)
if err != nil { if err != nil {
@ -166,6 +167,7 @@ func thereAreMessagesInMailboxesForAddressOfUser(mailboxNames, bddAddressID, bdd
return err return err
} }
} }
}
return nil return nil
} }