initial working command
This commit is contained in:
45
zfs_test.go
Normal file
45
zfs_test.go
Normal 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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user