-
Notifications
You must be signed in to change notification settings - Fork 9
Open
Milestone
Description
Dev story
Write a function/method that sorts an array in a similar way with the Linux command sort
Example:
sortedArray := sort(unsortedArray)Acceptance Criteria
- Use https://github.com/spf13/afero for filesystem abstraction
- Make sure it works cross-platform
- Put the function into
internal/utilspackage - For logging use https://github.com/Sirupsen/logrus
- Write a unit test
- Make sure there are testable examples
Hints:
- Writing a unit test for filesystem checking is not trivial. You should NOT create a real file on the system, because then your test will depend on the I/O of the file system itself. The last resort is mocking the filesystem. There are quite a few powerful libraries like spf13/afero for this purpose (mocking of a filesystem). These packages will create temporary files in the background and clean up afterward.
- As an exercise, try to write the test first. Let it fail. Then try to fix it, by writing the actual implementation of the function.
Extra Help:
- https://golangcode.com/check-if-a-file-exists/
- https://www.youtube.com/watch?v=ifBUfIb7kdo
- https://github.com/spf13/afero#using-afero-for-testing
- An example using Afero for testing: http://krsacme.com/golang-fs-tests/
- For logging https://linuxhint.com/golang-logrus-package/
NOTICE: If you are unable to mock this test, in worst case scenario, create a folder internal/utils/testdata and put actual files you can use for your test.
Metadata
Metadata
Assignees
Labels
No labels