mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-02-25 23:19:13 -06:00
add test coverage for panics
This commit is contained in:
@@ -13,9 +13,11 @@ func Test_mustUserConfigDir(t *testing.T) {
|
||||
extension string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want string
|
||||
name string
|
||||
args args
|
||||
want string
|
||||
resetHome bool
|
||||
panic bool
|
||||
}{
|
||||
{
|
||||
name: "fetch the default config location for the current user",
|
||||
@@ -25,12 +27,36 @@ func Test_mustUserConfigDir(t *testing.T) {
|
||||
},
|
||||
want: filepath.Join(configDir, "ocis", "testing"),
|
||||
},
|
||||
{
|
||||
name: "location cannot be determined becahse $HOME is not set",
|
||||
args: args{
|
||||
prefix: "ocis",
|
||||
extension: "testing",
|
||||
},
|
||||
want: filepath.Join(configDir, "ocis", "testing"),
|
||||
resetHome: true,
|
||||
panic: true,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
|
||||
if tt.resetHome {
|
||||
if err := os.Setenv("HOME", ""); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
defer func() {
|
||||
if r := recover(); r != nil && !tt.panic {
|
||||
t.Errorf("should have panicked!")
|
||||
}
|
||||
}()
|
||||
|
||||
if got := MustUserConfigDir(tt.args.prefix, tt.args.extension); got != tt.want {
|
||||
t.Errorf("MustUserConfigDir() = %v, want %v", got, tt.want)
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user