TestInitWriteError tests error handling when file write fails
(t *testing.T)
| 73 | |
| 74 | // TestInitWriteError tests error handling when file write fails |
| 75 | func TestInitWriteError(t *testing.T) { |
| 76 | // Skip this test if running as root (can write anywhere) |
| 77 | if runtime.GOOS != "windows" && os.Getuid() == 0 { |
| 78 | t.Skip("Cannot test write errors as root") |
| 79 | } |
| 80 | |
| 81 | // Use a platform-appropriate invalid path |
| 82 | invalidPath := "/dev/null/impossible/path/conf.yml" |
| 83 | if runtime.GOOS == "windows" { |
| 84 | invalidPath = `NUL\impossible\path\conf.yml` |
| 85 | } |
| 86 | |
| 87 | // Try to write to a read-only directory |
| 88 | err := Init(invalidPath, "test") |
| 89 | if err == nil { |
| 90 | t.Error("expected error when writing to invalid path, got nil") |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | // TestInitExistingFile tests that Init overwrites existing files |
| 95 | func TestInitExistingFile(t *testing.T) { |