mikelangelo-project / capstan

Capstan, a tool for packaging and running your application on OSv.
http://osv.io/capstan/
Other
19 stars 7 forks source link

Support lambda for DirEquals and TarGzEquals checkers #44

Closed miha-plesko closed 7 years ago

miha-plesko commented 7 years ago

Currently, DirEquals/TarGzEquals checkers are only able to check whether directory structure and file content is EXACTLY the same as expected. This brings a problem when we can't tell EXACLTY what the content will be, e.g. because Capstan prepends --env prefix to bootcommands in random order.

With this commit we extend DirEquals/TarGzEquals so that it now accepts map of expectations that can either contain expected string (EXACT match) or lambda function (more extensible match).

To reuse same logic for DirEquals and TarGzEquals checkers we quickly recaftor the code by introducing loadDir() and loadTarGz() auxilary functions.

miha-plesko commented 7 years ago

@gberginc I've opened the first PR. Please note that PRs here are at the lowest priority possible until August 15 so feel free not to review until then.

miha-plesko commented 7 years ago

To answer your question regarding bool vs error: it's about informing the user what the error was (where did the mismatch occur). If we only support bool then the compare function has no means of passing the error message to the checker.

In PRs that follow, we actually only make use of the error compare function in order to be able to provide accurate error message in case of mismatch. But I left support for bool just in case we need it in the future. That being said, would it be better to drop support for bool since we currently don't use it?

gberginc commented 7 years ago

When you put it like this, I guess it makes sense. You could probably also construct the error message at a place where the checker is called like you do here, but I don't know if there could be other errors that might be interesting.

In case you think returning bool would be useful in the future, you can leave it, otherwise I agree with the removal.

miha-plesko commented 7 years ago

I've removed support for bool functions, we're good to go.

gberginc commented 7 years ago

Thanks @miha-plesko. Please update #46 now as well.