MCPcopy Index your code
hub / github.com/cheat/cheat / TestInitWriteError

Function TestInitWriteError

internal/config/init_test.go:75–92  ·  view source on GitHub ↗

TestInitWriteError tests error handling when file write fails

(t *testing.T)

Source from the content-addressed store, hash-verified

73
74// TestInitWriteError tests error handling when file write fails
75func 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
95func TestInitExistingFile(t *testing.T) {

Callers

nothing calls this directly

Calls 1

InitFunction · 0.85

Tested by

no test coverage detected