T.Setenv calls os.Setenv and uses Cleanup to restore the environment variable to its original value after the test.
Cleanup registers a function to be called when the test and all its subtests complete.
TestMain is a handy way to do extra setup or teardown before or after a test executes.
This PR refactors tests in
cli/main_test.go
.Changes
os.Setenv
witht.Setenv
;init()
withTestMain
.t.Cleanup
for resetingAppFs
.Motivation
T.Setenv
callsos.Setenv
and usesCleanup
to restore the environment variable to its original value after the test.Cleanup
registers a function to be called when the test and all its subtests complete.TestMain
is a handy way to do extra setup or teardown before or after a test executes.