Skip to content

Commit

Permalink
fix: more strict testConnection.S and .Se matching.
Browse files Browse the repository at this point in the history
  • Loading branch information
cuthix authored and jameshoulahan committed Sep 16, 2022
1 parent 0b0cc86 commit c882e66
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 31 deletions.
6 changes: 3 additions & 3 deletions tests/capability_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ func TestCapability(t *testing.T) {
runOneToOneTest(t, defaultServerOptions(t), func(c *testConnection, _ *testSession) {
c.C("A001 Capability")
c.S(`* CAPABILITY IDLE IMAP4rev1 STARTTLS`)
c.S("A001 OK")
c.S("A001 OK CAPABILITY")

c.C(`A002 login "user" "pass"`)
c.S(`A002 OK [CAPABILITY IDLE IMAP4rev1 MOVE STARTTLS UIDPLUS UNSELECT]`)
c.S(`A002 OK [CAPABILITY IDLE IMAP4rev1 MOVE STARTTLS UIDPLUS UNSELECT] Logged in`)

c.C("A003 Capability")
c.S(`* CAPABILITY IDLE IMAP4rev1 MOVE STARTTLS UIDPLUS UNSELECT`)
c.S("A003 OK")
c.S("A003 OK CAPABILITY")
})
}
4 changes: 2 additions & 2 deletions tests/connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (s *testConnection) Cf(format string, a ...any) *testConnection {

// S expects that the server returns the given lines (in any order).
func (s *testConnection) S(want ...string) *testConnection {
return s.Sx(xslices.Map(want, func(want string) string { return regexp.QuoteMeta(want) })...)
return s.Sx(xslices.Map(want, func(want string) string { return "^" + regexp.QuoteMeta(want) + "\r\n" })...)
}

// Sx expects that the server returns lines matching the given regexps (in any order).
Expand Down Expand Up @@ -113,7 +113,7 @@ func (s *testConnection) Sx(want ...string) *testConnection {

// Se expects that the server eventually returns the given lines (in any order).
func (s *testConnection) Se(want ...string) *testConnection {
return s.Sxe(xslices.Map(want, func(want string) string { return regexp.QuoteMeta(want) })...)
return s.Sxe(xslices.Map(want, func(want string) string { return "^" + regexp.QuoteMeta(want) + "\r\n" })...)
}

// Sxe expects that the server eventually returns lines matching the given regexps (in any order).
Expand Down
10 changes: 5 additions & 5 deletions tests/draft_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestDraftScenario(t *testing.T) {
c.C("A002 NOOP")
c.S("* 1 EXISTS")
c.S("* 1 RECENT")
c.S("A002 OK")
c.OK("A002")

c.C("A003 FETCH 1 (BODY.PEEK[HEADER.FIELDS (To)])")
c.S("* 1 FETCH (BODY[HEADER.FIELDS (TO)] {10}\r\nTo: 3@3.pm)")
Expand All @@ -28,14 +28,14 @@ func TestDraftScenario(t *testing.T) {
s.messageCreated("user", mailboxID, []byte("To: 4@4.pm"), time.Now())
s.flush("user")

c.C("A002 NOOP")
c.C("A004 NOOP")
c.S("* 1 EXPUNGE")
c.S("* 1 EXISTS")
c.S("* 1 RECENT")
c.S("A002 OK")
c.OK("A004")

c.C("A003 FETCH 1 (BODY.PEEK[HEADER.FIELDS (To)])")
c.C("A005 FETCH 1 (BODY.PEEK[HEADER.FIELDS (To)])")
c.S("* 1 FETCH (BODY[HEADER.FIELDS (TO)] {10}\r\nTo: 4@4.pm)")
c.OK("A003")
c.OK("A005")
})
}
2 changes: 1 addition & 1 deletion tests/login_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,6 @@ func TestLoginLiteralFailure(t *testing.T) {
func TestLoginCapabilities(t *testing.T) {
runOneToOneTest(t, defaultServerOptions(t), func(c *testConnection, _ *testSession) {
c.C("A001 login user pass")
c.S(`A001 OK [CAPABILITY IDLE IMAP4rev1 MOVE STARTTLS UIDPLUS UNSELECT]`)
c.S(`A001 OK [CAPABILITY IDLE IMAP4rev1 MOVE STARTTLS UIDPLUS UNSELECT] Logged in`)
})
}
22 changes: 11 additions & 11 deletions tests/select_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,30 @@ func TestSelect(t *testing.T) {
c.S(`* FLAGS (\Deleted \Flagged \Seen)`,
`* 2 EXISTS`,
`* 2 RECENT`,
`* OK [UNSEEN 2]`,
`* OK [PERMANENTFLAGS (\Deleted \Flagged \Seen)]`,
`* OK [UIDNEXT 3]`,
`* OK [UIDVALIDITY 1]`)
`* OK [UNSEEN 2] Unseen messages`,
`* OK [PERMANENTFLAGS (\Deleted \Flagged \Seen)] Flags permitted`,
`* OK [UIDNEXT 3] Predicted next UID`,
`* OK [UIDVALIDITY 1] UIDs valid`)
c.S("A006 OK [READ-WRITE] SELECT")

// Selecting again modifies the RECENT value.
c.C("A006 select INBOX")
c.S(`* FLAGS (\Deleted \Flagged \Seen)`,
`* 2 EXISTS`,
`* 0 RECENT`,
`* OK [UNSEEN 2]`,
`* OK [PERMANENTFLAGS (\Deleted \Flagged \Seen)]`,
`* OK [UIDNEXT 3]`,
`* OK [UIDVALIDITY 1]`)
`* OK [UNSEEN 2] Unseen messages`,
`* OK [PERMANENTFLAGS (\Deleted \Flagged \Seen)] Flags permitted`,
`* OK [UIDNEXT 3] Predicted next UID`,
`* OK [UIDVALIDITY 1] UIDs valid`)
c.S("A006 OK [READ-WRITE] SELECT")

c.C("A007 select Archive")
c.S(`* FLAGS (\Deleted \Flagged \Seen)`,
`* 1 EXISTS`,
`* 1 RECENT`,
`* OK [PERMANENTFLAGS (\Deleted \Flagged \Seen)]`,
`* OK [UIDNEXT 2]`,
`* OK [UIDVALIDITY 1]`)
`* OK [PERMANENTFLAGS (\Deleted \Flagged \Seen)] Flags permitted`,
`* OK [UIDNEXT 2] Predicted next UID`,
`* OK [UIDVALIDITY 1] UIDs valid`)
c.S(`A007 OK [READ-WRITE] SELECT`)
})
}
Expand Down
2 changes: 1 addition & 1 deletion tests/sequence_range_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestSequenceRange(t *testing.T) {
}
c.OK(`A010`)
c.C(`A011 COPY 1,3:* mbox2`)
c.S(`A011`)
c.OK(`A011`)
c.C(`A012 COPY 6:* mbox2`).BAD(`A012`)
c.C(`A012 COPY 6:* mbox2`).BAD(`A012`)
c.C(`A013 MOVE 1,5,3 mbox2`)
Expand Down
16 changes: 8 additions & 8 deletions tests/updates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,23 +230,23 @@ func TestMessageSeenUpdate(t *testing.T) {
c.C("A001 SELECT mbox").OK("A001")

c.C("A002 FETCH 1 (FLAGS)")
c.S(`* 1 FETCH (FLAGS (\Recent)`)
c.S(`* 1 FETCH (FLAGS (\Recent))`)
c.OK("A002")

s.messageSeen("user", messageID, true)

c.C("A003 FETCH 1 (FLAGS)")
c.S(`* 1 FETCH (FLAGS (\Recent)`)
c.S(`* 1 FETCH (FLAGS (\Recent))`)
// Unilateral update arrives after fetch.
c.S(`* 1 FETCH (FLAGS (\Recent \Seen)`)
c.S(`* 1 FETCH (FLAGS (\Recent \Seen))`)
c.OK("A003")

s.messageSeen("user", messageID, false)

c.C("A004 FETCH 1 (FLAGS)")
c.S(`* 1 FETCH (FLAGS (\Recent \Seen)`)
c.S(`* 1 FETCH (FLAGS (\Recent \Seen))`)
// Unilateral update arrives after fetch.
c.S(`* 1 FETCH (FLAGS (\Recent)`)
c.S(`* 1 FETCH (FLAGS (\Recent))`)
c.OK("A004")
})
}
Expand All @@ -260,14 +260,14 @@ func TestMessageFlaggedUpdate(t *testing.T) {

s.messageFlagged("user", messageID, true)
c.C("A003 FETCH 1 (FLAGS)")
c.S(`* 1 FETCH (FLAGS (\Recent)`)
c.S(`* 1 FETCH (FLAGS (\Recent))`)
c.OK("A003")

s.messageFlagged("user", messageID, false)
c.C("A004 FETCH 1 (FLAGS)")
c.S(`* 1 FETCH (FLAGS (\Flagged \Recent)`)
c.S(`* 1 FETCH (FLAGS (\Flagged \Recent))`)
// Unilateral updates arrive afterwards.
c.S(`* 1 FETCH (FLAGS (\Recent)`)
c.S(`* 1 FETCH (FLAGS (\Recent))`)
c.OK("A004")
})
}
Expand Down

0 comments on commit c882e66

Please sign in to comment.