geofffranks / spruce

A BOSH template merge tool
MIT License
427 stars 77 forks source link

[fix issue #256] handle empty YAML files #314

Closed VasylTretiakov closed 4 years ago

VasylTretiakov commented 4 years ago

If the YAML file is [effectively] empty (i.e. does not contain the root hash/map), create an empty hash/map and display a message in debug instead of exiting with error. Fixes #256

VasylTretiakov commented 4 years ago

@geofffranks, thanks for the guidance and updated tests. Please review the latest code changes. The suggested approach consists in modifying the parseYAML([]byte) function to check if the YAML struct obtained from the byte array matches the same struct of an empty YAML doc before trying to obtain a hash/map from it. If so, the code returns an empty hash/map struct immediately to prevent errors that otherwise would be produced by the next processing steps. To let the project compile I had to update the empty YAML processing test. After compiling I did manual integration tests with the newly compiled spruce binary using YAML doc with a newline and another one with comment (like in the unit test). Mixing those in arbitrary order with YAML docs that do have meaningful data seems to produce the expected results. Please let me know if you feel like adding more automatic unit or integration tests.