We're using the new AWS Rust SDK, and we need a way of testing our code. localstack looks promising for end-to-end system tests, but it's not practical for unit testing.
What I want is a Rust crate that lets me spin up an emulator for S3 or SSM, point my AWS code at the emulator's URL, test the code, then tear down the emulator - all in Rust. I'd also want to be able to configure the emulator to simulate errors.
I couldn't find anything like that. Does anyone know of such a thing?
It'll be pretty clunky, but that gives you a way to mock the underlying requests and inject errors.
Say you working on an application which uses a database and wanted to write unit tests for the application logic. You wouldn't create a temporary database for each test, instead you would abstract out the data access logic into something like a Database trait with a get_user_by_id() method. Then, for the unit tests you pass in a mock implementation instead of the implementation backed by Postgres (or whatever).
That way your tests wouldn't also be testing your migrations, whatever you use for SQL mapping, your database driver, and the underlying database. That's good for both quick feedback (your test suite fails in a couple hundred milliseconds instead of after 10+ seconds) and only testing the code you wrote without needing to mock deep implementation details like Postgres's wire format.
Couldn't you do something similar where you abstract out AWS for your application logic and write unit tests that call mocks, then do your overall end-to-end testing with localstack?
That response from u/mikekchar is exactly what I had in mind, with the exception that I would always implement the HttpBinApi trait on a newtype so I can give it a constructor that is specific to my application (e.g. I might know we always use tokens for auth, so I would add a fn with_api_token(token: &str) -> Result<Self, Error> method to avoid the normal boilerplate).