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

initial sketch of a test friendly lambda context interface #52

Closed softprops closed 5 years ago

softprops commented 5 years ago

fixes: #51

@ilianaw I took an initial stab at this. let me know what you think. Context here is I'd like to improve the story around unit testing. Atm this is not possible because the new constructor is private to callers and even it were public it would be awkward to construct with a bring-your-own-py api.

I tried two approaches and settled on the second. I first tried extracting out LambdaContext into a trait but this required a change to the handler api so I punted on that. The second try was to make the existing LambdaContext type's a little more generalized. Rather than storing and operating on py objects it just operates on raw data. I created a new factory method named fake ( open to other suggestions ) that creates a fake LambdaContext which is only available in test contexts. This avoids any any bloat to production binaries. I also sketched out a few methods that serve as "builder" style api also only available in the test context. This leaves the production binary interface immutable, as it should be :)

Let me know what you think and if this looks good. I'll fill out the remaining builder methods.

softprops commented 5 years ago

@ilianaw thoughts on this? I'm aiming for a more straight fwd unit testing story for crowbar functions.

softprops commented 5 years ago

Friendly nudge :)

softprops commented 5 years ago

@ilianaw I saw the pull approval. Can this be merged?

softprops commented 5 years ago

Actually first I'll fill in the remainder of methods.

softprops commented 5 years ago

ok @ilianaw pushed up the remaining impl

softprops commented 5 years ago

Yep!