Skip to content

Add fake IMAP server for integration testing#3

Merged
dannywillems merged 6 commits intomasterfrom
add-fake-imap-server-tests
Feb 9, 2026
Merged

Add fake IMAP server for integration testing#3
dannywillems merged 6 commits intomasterfrom
add-fake-imap-server-tests

Conversation

@dannywillems
Copy link
Contributor

Summary

  • Add in-process fake IMAP server for integration testing that exercises the full connection lifecycle: TCP -> greeting -> STARTTLS -> TLS -> LOGIN -> commands -> LOGOUT
  • Add 7 integration tests covering all ProtonClient public methods: list_folders, fetch_uid, fetch_unseen, fetch_all, fetch_last_n, search, and empty mailbox handling
  • Server generates self-signed TLS certs at runtime via rcgen (no cert files needed)

Architecture

The fake server (tests/fake_imap/) implements enough of the IMAP protocol to test the client end-to-end:

IMAP Command What it does
STARTTLS Upgrade TCP to TLS
LOGIN Accept any credentials
LIST Return configured folders
SELECT Open a folder, return EXISTS/UIDVALIDITY
UID SEARCH Filter by UNSEEN or return all UIDs
UID FETCH Return email body via counted literals
LOGOUT Clean disconnect

Server code is heavily commented explaining the IMAP protocol at each step (educational).

New dev-dependencies

  • `rcgen = "0.13"` -- generate self-signed TLS certs at runtime (MIT/Apache-2.0)
  • `rustls-pemfile = "2"` -- parse PEM for rustls ServerConfig (MIT/Apache-2.0)

Test plan

  • `cargo test --test integration_test` -- all 7 tests pass
  • Clippy clean

Add an in-process fake IMAP server that exercises the full
connection lifecycle: TCP -> greeting -> STARTTLS -> TLS handshake
-> LOGIN -> commands -> LOGOUT.

The fake server generates self-signed certs at runtime via rcgen
and implements enough of the IMAP protocol (LIST, SELECT, UID
SEARCH, UID FETCH with counted literals, LOGOUT) to test all
ProtonClient public methods. Server code is heavily commented
explaining the IMAP protocol at each step.

7 integration tests cover: list_folders, fetch_uid, fetch_unseen,
fetch_all, fetch_last_n, search, and empty_mailbox.
- Move lint config from per-file attributes to [lints.clippy]
- Remove missing_errors_doc and missing_panics_doc allows
- Add # Errors doc sections to all public Result-returning fns
- Fix clippy issues: const fn, useless conversion, split_once,
  similar_names
Test all 6 CLI subcommands (folders, list --limit, list --unseen,
show, search, list --json) by spawning the binary against the fake
IMAP server and asserting on stdout.
Split the monolithic server.rs into one file per IMAP command handler
(login, logout, list, select, uid_search, uid_fetch) under handlers/.
Each handler is independently testable via tokio::io::duplex, adding
21 unit tests. Shared I/O helpers moved to io.rs.
@dannywillems dannywillems merged commit d55fd86 into master Feb 9, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant