gopass/pkg/fsutil/umask_test.go
Eng Zer Jun 840fb827ac
test: use T.Setenv to set env vars in tests (#2463)
This commit replaces `os.Setenv` with `t.Setenv` in tests. The
environment variable is automatically restored to its original value
when the test and all its subtests complete.

Reference: https://pkg.go.dev/testing#T.Setenv
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>

Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2022-12-11 12:51:59 +01:00

24 lines
410 B
Go

package fsutil
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestUmask(t *testing.T) {
for _, vn := range []string{"GOPASS_UMASK", "PASSWORD_STORE_UMASK"} {
for in, out := range map[string]int{
"002": 0o2,
"0777": 0o777,
"000": 0,
"07557575": 0o77,
} {
t.Run(vn, func(t *testing.T) {
t.Setenv(vn, in)
assert.Equal(t, out, Umask())
})
}
}
}