Skip to content

Commit a055254

Browse files
committed
domain: Add a function to get the qemu package version
This is a more detailed version string than is returned by Version(), allowing callers to distinguish between patch builds.
1 parent 39453ac commit a055254

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

qemu/domain.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,17 @@ func (d *Domain) Version() (string, error) {
346346
return response.Return.String(), nil
347347
}
348348

349+
// PackageVersion returns the domain's QEMU package version, the full build
350+
// information for QEMU.
351+
func (d *Domain) PackageVersion() (string, error) {
352+
vers, err := d.rm.QueryVersion()
353+
if err != nil {
354+
return "", err
355+
}
356+
357+
return vers.Package, nil
358+
}
359+
349360
// Events streams QEMU QMP events.
350361
// Two channels are returned, the first contains events emitted by the domain.
351362
// The second is used to signal completion of event processing.

qemu/version_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"testing"
1919

2020
"github.com/digitalocean/go-qemu/qmp"
21+
"github.com/digitalocean/go-qemu/qmp/raw"
2122
)
2223

2324
func TestVersion(t *testing.T) {
@@ -48,3 +49,33 @@ func TestVersion(t *testing.T) {
4849
t.Errorf("expected version %q, instead got %q", expected, v)
4950
}
5051
}
52+
53+
func TestPackageVersion(t *testing.T) {
54+
result := raw.VersionInfo{}
55+
result.Qemu.Major = 2
56+
result.Qemu.Minor = 8
57+
result.Qemu.Micro = 0
58+
result.Package = "(Debian 1:2.8+dfsg-3ubuntu2.4)"
59+
60+
d, done := testDomain(t, func(cmd qmp.Command) (interface{}, error) {
61+
if want, got := "query-version", cmd.Execute; want != got {
62+
t.Fatalf("unexpected QMP command:\n- want: %q\n- got: %q",
63+
want, got)
64+
}
65+
66+
return success{
67+
Return: result,
68+
}, nil
69+
})
70+
defer done()
71+
72+
v, err := d.PackageVersion()
73+
if err != nil {
74+
t.Error(err)
75+
}
76+
77+
expected := "(Debian 1:2.8+dfsg-3ubuntu2.4)"
78+
if v != expected {
79+
t.Errorf("expected package version %q, instead got %q", expected, v)
80+
}
81+
}

0 commit comments

Comments
 (0)