ribacq / tomato

Simple markdown-based, static website generator written in Go.
https://ribacq.github.io/tomato
zlib License
1 stars 0 forks source link

Mock a filesystem for the tests #4

Open ghost opened 6 years ago

ghost commented 6 years ago

It is important to be able to test the functions that use the file system. To solve this problem, a posibility is to use afero. Afero offers several advantages and provides an easy way to mock a file system.

If you think it's a good idea, then I'll propose a pull request.

ribacq commented 6 years ago

You are right, filesystem.go and a lot of tomato.go, if not all, could be tested via a mock file system. Would using afero requirere to change all current calls to package os to afero?

Sure, please do. Start with the tests of filesystem.go, and then we’ll have to discuss how to cut the main function into several parts.

ghost commented 6 years ago

Indeed, all calls must be replaced. However, the API is the same, so this is very simple. In addition, afero offers functions such as Remove, RemoveAll, DirExists or Exists which can replace certain calls made in tomato (at rm for example). The use of rm is making testing impossible, so this is very useful.