b3f24861c4
Replace the shell-script-based logmockzfs wrapper with a Go-native multi-personality binary (busybox-style). The platformtest binary now acts as a safety interposer for zfs/zpool when invoked via symlinks, validating that all commands reference the hardcoded test pool before delegating through sudo. Key changes: - New interposer.go: SetupInterposerPath creates a tmpdir with symlinks and replaces PATH; RunInterposer validates args and delegates via sudo - Pool name, image path, and mountpoint are now hardcoded constants - Remove ZpoolCreateArgs, Zpool struct, and CLI flags for pool config - Remove logmockzfs/ shell scripts (logzfsenv, zfs wrapper) - Simplify Makefile: no more logmockzfs invocation or root check - Add -no-interposer flag for direct execution as root - Safety: block -a (all) flags without pool reference, validate mountpoint paths against traversal, command-aware flag parsing Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
62 lines
1.3 KiB
Go
62 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/zrepl/zrepl/internal/platformtest"
|
|
)
|
|
|
|
// Idea taken from
|
|
// https://github.com/openSUSE/umoci/blob/v0.2.1/cmd/umoci/main_test.go
|
|
//
|
|
/* How to generate coverage:
|
|
go test -c -covermode=atomic -cover -coverpkg github.com/zrepl/zrepl/...
|
|
./harness.test -test.coverprofile=/tmp/harness.out \
|
|
-test.v __DEVEL--i-heard-you-like-tests
|
|
go tool cover -html=/tmp/harness.out -o /tmp/harness.html
|
|
*/
|
|
// Merge with existing coverage reports using gocovmerge:
|
|
// https://github.com/wadey/gocovmerge
|
|
|
|
func TestMain(t *testing.T) {
|
|
// Multi-personality: when invoked as zfs/zpool symlink, run interposer
|
|
switch filepath.Base(os.Args[0]) {
|
|
case "zfs":
|
|
os.Exit(platformtest.RunInterposer("zfs"))
|
|
case "zpool":
|
|
os.Exit(platformtest.RunInterposer("zpool"))
|
|
}
|
|
|
|
fmt.Println("incoming args: ", os.Args)
|
|
|
|
var (
|
|
args []string
|
|
run bool
|
|
startCaptureArgs bool
|
|
)
|
|
|
|
for i, arg := range os.Args {
|
|
switch {
|
|
case arg == "__DEVEL--i-heard-you-like-tests":
|
|
run = true
|
|
startCaptureArgs = true
|
|
case strings.HasPrefix(arg, "-test"):
|
|
case strings.HasPrefix(arg, "__DEVEL"):
|
|
case i == 0:
|
|
args = append(args, arg)
|
|
case startCaptureArgs:
|
|
args = append(args, arg)
|
|
}
|
|
}
|
|
os.Args = args
|
|
fmt.Println("using args: ", os.Args)
|
|
|
|
if run {
|
|
main()
|
|
}
|
|
}
|