| 1 | package guestos |
| 2 | |
| 3 | import ( |
| 4 | "os/exec" |
| 5 | "path/filepath" |
| 6 | "runtime" |
| 7 | "testing" |
| 8 | ) |
| 9 | |
| 10 | func TestHyperVReadOnlyQuery(t *testing.T) { |
| 11 | shell := "pwsh" |
| 12 | if runtime.GOOS == "windows" { |
| 13 | shell = "powershell.exe" |
| 14 | } |
| 15 | binary, err := exec.LookPath(shell) |
| 16 | if err != nil { |
| 17 | t.Skipf("%s is not installed", shell) |
| 18 | } |
| 19 | query, err := filepath.Abs("hyperv_instance.ps1") |
| 20 | if err != nil { |
| 21 | t.Fatal(err) |
| 22 | } |
| 23 | cmd := exec.CommandContext(t.Context(), binary, "-NoProfile", "-NonInteractive", "-File", filepath.Join("testdata", "hyperv_instance.ps1"), "-Query", query) |
| 24 | if output, err := cmd.CombinedOutput(); err != nil { |
| 25 | t.Fatalf("Hyper-V query: %v\n%s", err, output) |
| 26 | } |
| 27 | } |