Re:Serverless: A lesson learned the hard way
by chrisco255 on Thursday August 10, 2017 @02:50PM
(#14982872)
The developer should be writing unit tests for their code so they can avoid small mistakes like this.
[ Parent
| on HN ]
Re:Serverless: A lesson learned the hard way
by codedokode on Thursday August 10, 2017 @04:45PM
(#14984057)
It is impractical to cover every line of code with tests (it would get too expensive). Futhermore, in this case the author would have to test production config interacting with Amazon servers rather than a piece of code.
And even 100% code coverage doesn't find all possible errors.
Re:Serverless: A lesson learned the hard way
by Piskvorrr on Thursday August 10, 2017 @05:06PM
(#14984281)
Do you need to cover every _line_ of code, or do you need to test resulting behavior? Also, while nothing is 100% foolproof, the example here would probably have been caught.
Re:Serverless: A lesson learned the hard way
by wolfi1 on Friday August 11, 2017 @03:56AM
(#14987512)
I doubt this, a unit test wouldn't have covered the infinite triggering of the created events
Re:Serverless: A lesson learned the hard way
by chrisco255 on Thursday August 10, 2017 @05:43PM
(#14984593)
> because of a refactor, I forgot the return statement and it just continued overwriting the file again
Unit tests are specifically useful for refactors. You can refactor your code and ensure that it behaves as intended. Integration tests are great, too, don't get me wrong. Either or both would have probably caught this.
Re:Serverless: A lesson learned the hard way
by jbergens on Friday August 11, 2017 @02:34AM
(#14987128)
this was a problem involving multiple parts, unit tests normally don't catches this. You need an integration/functional test and that can be much more time consuming to write for all "integrations" and code paths.
Re:Serverless: A lesson learned the hard way
by jo909 on Friday August 11, 2017 @04:34AM
(#14987696)
It was a single function that changed behavior after a refactoring. It did work where it did not need to, because the work was already done on the object. This is only hard if you don't test at all and can't already mock the object download/upload or don't have pure functions.
Re:Serverless: A lesson learned the hard way
by jbergens on Friday August 11, 2017 @06:04AM
(#14988094)
In this case it might have helped, I didn't read the code, but in a more general case these kind of things are rarely found by unit tests. I still doubt that the triggering caused by the file change would have been found in a unit test.
Re:Serverless: A lesson learned the hard way
by chrisco255 on Thursday August 10, 2017 @04:14PM
(#14983704)
Down vote for advocating for unit tests? That's just good practice in general.