71 lines
2.8 KiB
Go
71 lines
2.8 KiB
Go
package state
|
|
|
|
import (
|
|
"os"
|
|
"sync"
|
|
)
|
|
|
|
var testHookOverrideMu sync.Mutex
|
|
|
|
// TestHookQuarantineCorruptFile runs one orchestration or CLI step.
|
|
// Signature: TestHookQuarantineCorruptFile(path string, payload []byte, replacement []byte, mode os.FileMode) error.
|
|
// Why: exposes corrupt-file healing internals to the top-level testing module without package-local tests.
|
|
func TestHookQuarantineCorruptFile(path string, payload []byte, replacement []byte, mode os.FileMode) error {
|
|
return quarantineCorruptFile(path, payload, replacement, mode)
|
|
}
|
|
|
|
// TestHookWriteIntentDefault runs one orchestration or CLI step.
|
|
// Signature: TestHookWriteIntentDefault(path string, in Intent) error.
|
|
// Why: lets top-level tests delegate to production WriteIntent behavior while
|
|
// selectively forcing deterministic failures for specific branches.
|
|
func TestHookWriteIntentDefault(path string, in Intent) error {
|
|
return writeIntentDefault(path, in)
|
|
}
|
|
|
|
// TestHookSetWriteIntentOverride runs one orchestration or CLI step.
|
|
// Signature: TestHookSetWriteIntentOverride(fn func(path string, in Intent) error) (restore func()).
|
|
// Why: enables deterministic intent-write failure injection from the top-level
|
|
// testing module when tests run as root.
|
|
func TestHookSetWriteIntentOverride(fn func(path string, in Intent) error) (restore func()) {
|
|
testHookOverrideMu.Lock()
|
|
prev := writeIntentImpl
|
|
if fn == nil {
|
|
writeIntentImpl = writeIntentDefault
|
|
} else {
|
|
writeIntentImpl = fn
|
|
}
|
|
testHookOverrideMu.Unlock()
|
|
return func() {
|
|
testHookOverrideMu.Lock()
|
|
writeIntentImpl = prev
|
|
testHookOverrideMu.Unlock()
|
|
}
|
|
}
|
|
|
|
// TestHookQuarantineCorruptFileDefault runs one orchestration or CLI step.
|
|
// Signature: TestHookQuarantineCorruptFileDefault(path string, payload []byte, replacement []byte, mode os.FileMode) error.
|
|
// Why: lets top-level tests fall through to production quarantine behavior when
|
|
// they only want to force a subset of calls.
|
|
func TestHookQuarantineCorruptFileDefault(path string, payload []byte, replacement []byte, mode os.FileMode) error {
|
|
return quarantineCorruptFileDefault(path, payload, replacement, mode)
|
|
}
|
|
|
|
// TestHookSetQuarantineCorruptFileOverride runs one orchestration or CLI step.
|
|
// Signature: TestHookSetQuarantineCorruptFileOverride(fn func(path string, payload []byte, replacement []byte, mode os.FileMode) error) (restore func()).
|
|
// Why: enables deterministic auto-heal failure tests in privileged/root execution.
|
|
func TestHookSetQuarantineCorruptFileOverride(fn func(path string, payload []byte, replacement []byte, mode os.FileMode) error) (restore func()) {
|
|
testHookOverrideMu.Lock()
|
|
prev := quarantineCorruptFileImpl
|
|
if fn == nil {
|
|
quarantineCorruptFileImpl = quarantineCorruptFileDefault
|
|
} else {
|
|
quarantineCorruptFileImpl = fn
|
|
}
|
|
testHookOverrideMu.Unlock()
|
|
return func() {
|
|
testHookOverrideMu.Lock()
|
|
quarantineCorruptFileImpl = prev
|
|
testHookOverrideMu.Unlock()
|
|
}
|
|
}
|