initial working command

This commit is contained in:
Sam Hoffman
2026-01-30 15:14:25 -05:00
commit e325fcca1a
5 changed files with 289 additions and 0 deletions

45
zfs_test.go Normal file
View File

@@ -0,0 +1,45 @@
package main_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)
}
}