fix: env var test updated for panic

fix: recover in test
This commit is contained in:
Slug-Boi
2025-06-03 19:59:00 +02:00
parent ff9b8739cb
commit 1f7e571fb9
+16 -9
View File
@@ -173,16 +173,23 @@ func Test_FindAuthorFileEnv(t *testing.T) {
// Test Find_authorfile with env var // Test Find_authorfile with env var
setup() setup()
defer teardown() defer teardown()
os.Setenv("author_file", "")
authorfile := utils.Find_authorfile()
configdir, err := os.UserConfigDir()
if err != nil {
t.Fatalf("Failed to get user config directory: %v", err)
}
if authorfile != configdir+"/cocommit/authors.json" {
t.Errorf("Find_authorfile() = %v; want %v", authorfile, configdir+"/cocommit/authors.json")
}
// Save original environment variable
originalAuthorFile := os.Getenv("author_file")
defer func() {
// Reset environment variable
os.Setenv("author_file", originalAuthorFile)
if r := recover(); r == nil {
t.Errorf("Find_authorfile() did not panic")
}
}()
// Set an invalid environment variable to trigger panic
os.Setenv("author_file", "")
utils.Find_authorfile()
} }
func Test_CreateAuthorPanicOnFileError(t *testing.T) { func Test_CreateAuthorPanicOnFileError(t *testing.T) {