go-sdk icon indicating copy to clipboard operation
go-sdk copied to clipboard

How to properly test

Open qustavo opened this issue 1 year ago • 5 comments

I'm opening this issue to ask how should I test components that are using dapr. In my case, I needed to make sure that my code was using pubsub correctly. I ended up exec.Command("dapr", "run", ... more args ...) and creating a Client and a Service that conneted to the dapr daemon. While this worked, I wonder if there is a programmatic way to do this. I skim through this repo and dapr/dapr and I could find anything. Is this the right way to test? is there a better one?

Thanks!

qustavo avatar Jan 11 '24 12:01 qustavo

Depends what test you are looking for. For my case, I used testcontainers to spin-up containers and test Dapr functionalities during the integration testing phase. It's particularly useful when a service provider doesn't offer a way to test their proprietary service locally. With Dapr it's just a matter of swapping a container with an open-source alternative.

You can find an example in the following repository: https://github.com/etiennetremel/testcontainers-dapr-example

etiennetremel avatar Jan 22 '24 12:01 etiennetremel

I'm following a similar approach but without docker, just by running the binnary (os.Exec). Using docker sounds interesting, portable and contained, specially when it comes to finding unused ports. Although it would be nice to have some package implementing a testing server. Have you experimented creating a grpc server for test?

qustavo avatar Jan 22 '24 20:01 qustavo

I haven't played with GRPC for tests, but I wouldn't expect much difference from a standard HTTP server

etiennetremel avatar Jan 29 '24 11:01 etiennetremel

have you started a HTTP server for tests?

qustavo avatar Jan 29 '24 14:01 qustavo

The examples in this repo are validated using mechanical markdown - https://github.com/dapr/mechanical-markdown Have a look at the validation github workflow along with the README files which validates the output against expected.

mikeee avatar Jan 29 '24 14:01 mikeee