Files
thanks/internal/zfs/zfs_test.go
2026-01-30 17:10:13 -05:00

46 lines
869 B
Go

package zfs_test
import (
"fmt"
"os/exec"
"testing"
)
type zfscmd struct {
cmd string
}
type zrunner struct {
cmd string
args []string
}
func (z *zrunner) Run(zcmd *zfscmd, fargs ...any) ([]byte, error) {
var zargs string
if len(fargs) > 0 {
zargs = fmt.Sprintf(zcmd.cmd, fargs...)
} else {
zargs = zcmd.cmd
}
largs := append(z.args, zargs)
cmd := exec.Command(z.cmd, largs...)
return cmd.CombinedOutput()
}
func Test_ZFSCommand(t *testing.T) {
cmd := zfscmd{"zfs list -j %s"}
runner := zrunner{"/bin/sh", []string{"-c"}}
sshRunner := zrunner{"ssh", []string{"root@10.10.10.254"}}
out, err := runner.Run(&cmd, "zroot/ROOT/gentoo")
if err != nil {
t.Errorf("zrunner failed: %s \n\n%s", err.Error(), out)
}
out, err = sshRunner.Run(&cmd, "zroot/ROOT")
if err != nil {
t.Errorf("SSH zrunner failed: %s \n\n%s", err.Error(), out)
}
}