fermyon / spin-dotnet-sdk

Apache License 2.0
43 stars 11 forks source link

Question on testing/mocking internals #38

Open christophwille opened 2 years ago

christophwille commented 2 years ago

I wrote myself a simple do-nothing sample and added basic unit tests that run outside WASM:

https://github.com/christophwille/SpinHello/blob/main/src/Tests/SampleUnitTests.cs

Going one step further would be taking https://github.com/fermyon/spin-dotnet-sdk/blob/c12d70e36a274396c7b1ded7a06ec913748bdb3d/samples/hello-world/Handler.cs#L43 And here the question comes up of how to properly mock that guy - do you envision me to wrap it in a service that I replace (IOutboundHttp with one real implemenation and one Mock) or is this an area that is "undefined" as of now?

christophwille commented 2 years ago

I wrote myself a small wrapper in my sample app for HttpOutbound.Send. Your take?

Aside: It is super-confusing that between HttpRequest and HttpResponse the StatusCode props are different underlying types. I probably would like it better not seeing System.Net anywhere to make sure there are no mishaps in copy/paste (worded that way because it is only hunch).

itowlson commented 2 years ago

Thanks for the feedback!

Re mocking outbound HTTP, you're right, the static member is impractical to mock. Longer term, I'm hoping we can align more with the Microsoft HTTP API, using the WASI interface only as the low-level transport handler, but there are challenges to doing that. But for now, your approach of to writing a small wrapper is the right way to go.

Re status codes, that's a good point and we'll have a think about what to unify on.

Thanks again for kicking the tyres and for taking the time to let us know what issues you're running into!