probonopd / uploadtool

Upload builds to GitHub Releases easily
MIT License
100 stars 41 forks source link

Unit tests to prevent bad commits to pass #11

Open TheAssassin opened 6 years ago

TheAssassin commented 6 years ago

As seen in #10, some bugs might pass, leading to broken builds. We should add some tests.

There is no real "dummy" or "sandbox" GitHub API (like there is one for many other REST APIs, e.g. https://developer.paypal.com/docs/integration/direct/payments/test-the-api/), so the question is how to realize the tests.

In an example from the GitHub API docs they just have an extra repository whose sole purpose is to serve as a sandbox for API calls. However, I don't think that's really practicable, it'll generate a lot of unnecessary notifications etc.

An alternative is to set up a fake API server as a fixture for the tests. There's a bunch of possibilities, e.g., https://github.com/localmed/api-mock, https://github.com/typicode/json-server or https://github.com/basicallydan/interfake (did not test any of them, just the result of some searches). Also, we could roll our own based on a little Flask script.

Both options have pros and cons -- the real GitHub API will always provide the most realistic experience, whereas a fake API might not react to changes in the GitHub API spec in time. I'd probably go with writing a little Flask based API server, and redirect all the API calls to that service (e.g., by making the API address upload.sh uses configurable using an environment variable).

A tool used as widely as this one has to work reliably. And we all know untested code is broken code.

probonopd commented 6 years ago

A further alternative would be to copy the script into another project, do the changes there and use it for a while, and only thereafter make the changes here.