iliana / rust-crowbar

Wrapper to simplify writing AWS Lambda functions in Rust (using the Python execution environment)
https://docs.rs/crowbar
Apache License 2.0
197 stars 16 forks source link

Consider unit test friendly interface for LambdaContext #51

Closed softprops closed 5 years ago

softprops commented 6 years ago

At the moment this type is not easy to construct in a test setting though serde json values and result types are. It would be nice is this where either a trait with a default pyobject backed impl or LambdaContext has a constuctor that made testing easier.

softprops commented 6 years ago

actually you can't construct these at all in unit tests because the new fn is private.

I took at stab at turning this into a trait called LambdaContext and renaming the current struct to PyLambdaContext and creating an impl of LambdaContext for that however that caused a nuance in the handler method. It's signature need to change to take a Box'd version of a reference.

I'm going to take a stab at not changing the the type itself but its implementation default. I think it only really needs to store its internal str storage and a closure to the the remaining time. I could create cfg(test) methods then to help populate those. I'll push up and you can let me know what you think @ilianaw

softprops commented 6 years ago

actually rust makes it awkward to store a closure in a struct as well :/