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.
One of the most annoying things about testing any code that depends on
user.Current()
and theHomeDir()
method is that this cannot easily be mocked forcing use of a container just to do simply tests. By providing acmdtab.User
we can easily set this to mock for tests.The default value should be
user.Current()
atinit()
time and set at that time. Applications usingcmdtab
should then usecmdtab.User
instead of calling into theos/user
package.This has the added advantage of providing logic to detect and avoid cgo dependencies.