go/fs_example_test.go
Snider 1cafdff227 feat: zero os/errors/filepath/json/exec/runtime in tests — full dogfood
Eliminated ALL disallowed imports from test files:
- os.WriteFile → Fs.Write()
- os.ReadFile → Fs.Read()
- os.ReadDir → Fs.List()
- os.MkdirAll → Fs.EnsureDir()
- os.MkdirTemp → Fs.TempDir()
- os.DirFS → core.DirFS()
- os.UserHomeDir → Env("DIR_HOME")
- os.Exit/Args/Environ → removed subprocess tests (RunE covers behaviour)
- Added Fs.TempDir() and core.DirFS() primitives

558 tests, 84.6% coverage. Core's tests now exclusively use Core's
own primitives. The quality gate from RFC-025 Principle 9 has zero
violations in Core's own codebase.

Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-25 19:23:11 +00:00

43 lines
830 B
Go

package core_test
import (
"fmt"
. "dappco.re/go/core"
)
func ExampleFs_WriteAtomic() {
f := (&Fs{}).New("/")
dir := f.TempDir("example")
defer f.DeleteAll(dir)
path := Path(dir, "status.json")
f.WriteAtomic(path, `{"status":"completed"}`)
r := f.Read(path)
fmt.Println(r.Value)
// Output: {"status":"completed"}
}
func ExampleFs_NewUnrestricted() {
f := (&Fs{}).New("/")
dir := f.TempDir("example")
defer f.DeleteAll(dir)
// Write outside sandbox using Core's Fs
outside := Path(dir, "outside.txt")
f.Write(outside, "hello")
sandbox := (&Fs{}).New(Path(dir, "sandbox"))
unrestricted := sandbox.NewUnrestricted()
r := unrestricted.Read(outside)
fmt.Println(r.Value)
// Output: hello
}
func ExampleFs_Root() {
f := (&Fs{}).New("/srv/workspaces")
fmt.Println(f.Root())
// Output: /srv/workspaces
}