Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more serious testing #101

Open
6 tasks
jonhoo opened this issue Nov 23, 2018 · 0 comments
Open
6 tasks

Add more serious testing #101

jonhoo opened this issue Nov 23, 2018 · 0 comments
Labels
good first issue Good for newcomers help wanted Extra attention is needed tombstone A reference to an old issue on mattnenterprise/rust-imap

Comments

@jonhoo
Copy link
Owner

jonhoo commented Nov 23, 2018

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) 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/, 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 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:

Writing tests

Integration tests for imap are super easy to write, and generally they all follow the same basic recipe. Use lettre to send some e-mails, and 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

#[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 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 mattnenterprise/rust-imap#101.

@jonhoo jonhoo added enhancement New feature or request help wanted Extra attention is needed good first issue Good for newcomers tombstone A reference to an old issue on mattnenterprise/rust-imap labels Nov 23, 2018
jonhoo added a commit that referenced this issue Nov 23, 2018
This uses [GreenMail's Docker
image](http://www.icegreen.com/greenmail/#deploy_docker_standalone) to
spin up a real SMTP+IMAP server on Travis, and then runs a series of
integration tests against it by sending e-mails using
[`lettre`](https://crates.io/crates/lettre) and checking that we can
receive them correctly.

A start on #101.
@jonhoo jonhoo added this to the imap 1.0 milestone Nov 23, 2018
jonhoo added a commit that referenced this issue Nov 23, 2018
This uses [GreenMail's Docker
image](http://www.icegreen.com/greenmail/#deploy_docker_standalone) to
spin up a real SMTP+IMAP server on Travis, and then runs a series of
integration tests against it by sending e-mails using
[`lettre`](https://crates.io/crates/lettre) and checking that we can
receive them correctly.

A start on #101.
jonhoo added a commit that referenced this issue Nov 24, 2018
This uses [GreenMail's Docker
image](http://www.icegreen.com/greenmail/#deploy_docker_standalone) to
spin up a real SMTP+IMAP server on Travis, and then runs a series of
integration tests against it by sending e-mails using
[`lettre`](https://crates.io/crates/lettre) and checking that we can
receive them correctly.

A start on #101.
@jonhoo jonhoo removed the enhancement New feature or request label Nov 24, 2018
@jonhoo jonhoo removed this from the imap 1.0 milestone Apr 20, 2021
@jonhoo jonhoo pinned this issue Apr 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed tombstone A reference to an old issue on mattnenterprise/rust-imap
Projects
None yet
Development

No branches or pull requests

1 participant