-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Add test for GetMailboxMessageCounts
- Loading branch information
1 parent
c99ec61
commit 1d8260c
Showing
3 changed files
with
50 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package tests | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/ProtonMail/gluon/events" | ||
goimap "github.com/emersion/go-imap" | ||
"github.com/emersion/go-imap/client" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestCounts(t *testing.T) { | ||
dir := t.TempDir() | ||
|
||
runOneToOneTestClientWithAuth(t, defaultServerOptions(t, withDataDir(dir)), func(client *client.Client, s *testSession) { | ||
for _, count := range getEvent[events.UserAdded](s.eventCh).Counts { | ||
require.Equal(t, 0, count) | ||
} | ||
|
||
for i := 0; i < 10; i++ { | ||
require.NoError(t, doAppendWithClientFromFile(t, client, "INBOX", "testdata/afternoon-meeting.eml", time.Now(), goimap.SeenFlag)) | ||
} | ||
}) | ||
|
||
runOneToOneTestClientWithAuth(t, defaultServerOptions(t, withDataDir(dir)), func(_ *client.Client, s *testSession) { | ||
for _, count := range getEvent[events.UserAdded](s.eventCh).Counts { | ||
require.Equal(t, 10, count) | ||
} | ||
}) | ||
} | ||
|
||
func getEvent[T any](eventCh <-chan events.Event) T { | ||
for event := range eventCh { | ||
if event, ok := event.(T); ok { | ||
return event | ||
} | ||
} | ||
|
||
panic("no event") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters