-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from arnisoph/main_tests
Increase test coverage in cmd/postisto/
- Loading branch information
Showing
5 changed files
with
115 additions
and
6 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"github.com/arnisoph/postisto/pkg/server" | ||
"github.com/arnisoph/postisto/test/integration" | ||
"github.com/stretchr/testify/require" | ||
"io/ioutil" | ||
"testing" | ||
) | ||
|
||
func TestNewApp(t *testing.T) { | ||
app := newApp() | ||
require := require.New(t) | ||
|
||
// ACTUAL TESTS BELOW | ||
require.Equal("quite okay mail-sorting", app.Usage) | ||
} | ||
|
||
func TestRunApp(t *testing.T) { | ||
require := require.New(t) | ||
|
||
// Create local test IMAP server | ||
testContainer := integration.NewTestContainer() | ||
acc := integration.NewAccount(t, testContainer.IP, "test", "test", testContainer.Imap, true, false, true, nil, testContainer.Redis) | ||
|
||
// Simulate new unsorted mails by uploading | ||
for _, mailNum := range []int{1, 2, 3, 4} { | ||
require.NotNil(acc) | ||
require.NotNil(acc.Connection) | ||
require.NotNil(*acc.InputMailbox) | ||
require.Nil(acc.Connection.Upload(fmt.Sprintf("../../test/data/mails/log%v.txt", mailNum), *acc.InputMailbox, nil)) | ||
} | ||
|
||
// Write exposed port to disk | ||
portConfig := | ||
"accounts:\n" + | ||
" local_imap_server:\n" + | ||
" enable: true\n" + | ||
" connection:\n" + | ||
" server: localhost\n" + | ||
" username: test\n" + | ||
" password: test\n" + | ||
fmt.Sprintf(" port: %v\n", testContainer.Imap) + | ||
" cacertfile: ../../test/data/certs/ca.pem" | ||
require.NoError(ioutil.WriteFile("../../test/data/configs/valid/local_imap_server/TestStartApp/.local.acc.yaml", []byte(portConfig), 0644)) | ||
|
||
// ACTUAL TESTS BELOW | ||
require.EqualError(runApp("does-not exist", "debug", false, 42, true), "lstat does-not exist: no such file or directory") | ||
require.NoError(runApp("../../test/data/configs/valid/local_imap_server/TestStartApp/", "debug", false, 42, true)) | ||
|
||
// Verify results | ||
fetchedMails, err := acc.Connection.Search(*acc.InputMailbox, nil, []string{server.FlaggedFlag}) | ||
require.Nil(err) | ||
require.Equal(0, len(fetchedMails), "Unexpected num of mails in mailbox %v", *acc.InputMailbox) | ||
|
||
fetchedMails, err = acc.Connection.Search("MyTarget", nil, []string{server.FlaggedFlag}) | ||
require.Nil(err) | ||
require.Equal(3, len(fetchedMails), "Unexpected num of mails in mailbox %v", "MyTarget") | ||
|
||
fetchedMails, err = acc.Connection.Search("MailFilterTest-TestRegex", nil, []string{server.FlaggedFlag}) | ||
require.Nil(err) | ||
require.Equal(1, len(fetchedMails), "Unexpected num of mails in mailbox %v", "MailFilterTest-TestRegex") | ||
} |
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
22 changes: 22 additions & 0 deletions
22
test/data/configs/valid/local_imap_server/TestStartApp/filters.yaml
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,22 @@ | ||
# vim: ts=2 sw=2 et | ||
|
||
filters: | ||
local_imap_server: | ||
main: | ||
commands: | ||
move: MyTarget | ||
rules: | ||
- and: | ||
- from: | ||
- "@youth4work.com" | ||
test_regex: | ||
commands: | ||
move: MailFilterTest-TestRegex | ||
rules: | ||
- and: | ||
- from: | ||
- '^.*@bigrock\.com.*$' | ||
- delivered-to: | ||
- cyberzonec.in | ||
- content-type: | ||
- ^(?:text/html|text/plain).*$ |