Documentation
¶
Overview ¶
Package writeguard stops a test process from writing under the developer's real ocfp directories.
Every function that writes ocfp config, state, data, keys, locks, or logs calls Check with the path it is about to write. In a real run Check returns at once, because only a test process sets EnvVar. In a test process it panics, with the stack of the write, when the path lies under one of the developer's real ocfp directories.
The real directories come from the passwd entry, not from $HOME or the XDG variables, because a test process points those at a temporary tree. A guard that read them would see that tree as the real home and stop every legitimate write.
Index ¶
Constants ¶
const EnvVar = "OCFP_TEST_SAFETY_GUARD"
EnvVar marks a test process. A test binary's TestMain sets it, and a real run never does.
const RootsEnvVar = "OCFP_TEST_SAFETY_GUARD_ROOTS"
RootsEnvVar lists more directories to guard, separated by os.PathListSeparator. A test binary's TestMain sets it to the ocfp directories that HOME, the XDG variables, and OCFP_HOME named before it moved them. A developer whose real directories aren't the defaults keeps them guarded that way, and so does a process with no passwd entry.
Variables ¶
This section is empty.
Functions ¶
func Check ¶
func Check(operation, path string)
Check panics when this is a test process and path lies under one of the developer's real ocfp directories. operation names the write in the panic message. An empty path passes, since it names no directory.
When this process has no passwd home and RootsEnvVar is empty, Check panics too. A test process that can't tell where the real directories are can't prove that it stays out of them.
func OverrideRealHome ¶
func OverrideRealHome(dir string) func()
OverrideRealHome makes Check treat dir as the developer's real home until the returned function runs. A test uses it to prove that a write under the real directories panics, without writing under them. It must not run in parallel with another test that calls it.
func Roots ¶
Roots returns the developer's real ocfp directories. They are the legacy ~/.ocfp and the XDG config, state, data, and cache directories under the passwd home, followed by any that RootsEnvVar lists. A root that a symbolic link leads to appears twice, once by each name. Without a passwd home, Roots returns those that RootsEnvVar lists, and it fails when that list is empty too.
Types ¶
This section is empty.