Add more serious testing
- Dominant language
- Rust
- Stars
- 583
- Forks
- 94
- PR merge metrics
- No merged PRs in 30d
Description
A fellow tester! How exciting! Welcome!
Since #102, the `imap` crate gained the ability to run full IMAP integration tests against a "real" IMAP server ([GreenMail](http://www.icegreen.com/greenmail/)) running in a Docker container. That server supports both SMTP (for sending mail) and IMAP (for receiving them), and is particularly well suited for testing as it automatically creates accounts as they are accessed.
While `imap` already has a few integration tests in [`tests/`](https://github.com/jonhoo/rust-imap/tree/master/tests), they are, at the time of writing, fairly rudimentary. We can do better. And you can help! And hey, if you add tests, you may also be able to improve the [code coverage](https://codecov.io/gh/jonhoo/rust-imap) and make the @codecov-io bot happy!
## Inspiration
In general, you can never have too much testing, especially for a crate like `imap` which has to interact with "the real world", which often misbehaves in various odd ways. Here are a few ways you can help expand `imap`'s testing story:
- [ ] Port over tests from [Ruby's `Net::IMAP`](https://github.com/ruby/ruby/tree/trunk/test/net/imap)
- [ ] Port over tests from [Go's `imap::client`](https://github.com/emersion/go-imap/tree/v1/client)
- [ ] Port over tests from [Node's `node-imap`](https://github.com/mscdex/node-imap/tree/master/test)
- [ ] Port over tests from [Perl's `Mail::IMAPClient`](https://metacpan.org/source/DJKERNEN/Mail-IMAPClient-2.2.9/t/basic.t)
- [ ] Port over tests from [Dovecot's `imaptest` scripted tests](https://github.com/dovecot/imaptest/tree/master/src/tests)
- [ ] Write tests that exercise the examples client-server interactions from the [IMAP RFC](https://tools.ietf.org/html/rfc3501)
- Or just write up tests that represent operations you've done or observed in a real deployment!
## Writing tests
Integration tests for `imap` are super easy to write, and generally they all follow the same basic recipe. Use [`lettre`](https://docs.rs/lettre/) to send some e-mails, and [`imap`](https://docs.rs/imap/) to create mailboxes, move e-mails, expunge, delete, store, append, list, and whatever else you may feel like doing. The `session` and `smpt` helper functions give you authenticated clients for `imap` and `lettre` respectively. It looks something like this
```rust
#[test]
fn mytest() {
// set a unique e-mail account to run for your test.
let to = "mytest@localhost";
// log in to the IMAP server
let mut c = session(to);
// log in to the SMTP server
let mut s = smtp(to);
// and then send ourselves an e-mail
let e = lettre_email::Email::builder()
.from("sender@localhost")
.to(to)
.subject("My first e-mail")
.build()
.unwrap();
s.send(e.into()).unwrap();
// now we should see the e-mail!
c.select("INBOX").unwrap();
let inbox = c.search("ALL").unwrap();
assert_eq!(inbox.len(), 1);
// let's delete it to clean up after the test
c.store("1", "+FLAGS (\\Deleted)").unwrap();
c.expunge().unwrap();
}
```
If you want something more substantial to look at, the [`inbox_uid` integration test](https://github.com/jonhoo/rust-imap/blob/e7e20c08e96ed1a4532e2b7e4f56be76c9d361ed/tests/imap_integration.rs#L150) is probably a good place to start.
To ensure that we can run multiple tests in parallel, you should make sure that each test you write uses a dedicated user account (e-mail address) GreenMail will automatically create accounts for new e-mail addresses it sees, so all you should need to do is to decide how to name them (the name of the test + `@localhost` is probably a good choice). You'll also want to do cleanup at the end of your test so that we can run the same test more than once without restarting the server!
## What now?
Go write some tests and submit a pull request :D
You're awesome!
This issue originally resided in https://github.com/mattnenterprise/rust-imap/issues/101.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.