rwxrob / cmdtab

Apache License 2.0
13 stars 0 forks source link

Add UserHome for better testing #16

Closed rwxrob closed 3 years ago

rwxrob commented 3 years ago

One of the most annoying things about testing any code that depends on user.Current() and the HomeDir() method is that this cannot easily be mocked forcing use of a container just to do simply tests. By providing a cmdtab.User we can easily set this to mock for tests.

The default value should be user.Current() at init() time and set at that time. Applications using cmdtab should then use cmdtab.User instead of calling into the os/user package.

This has the added advantage of providing logic to detect and avoid cgo dependencies.