On Wed, May 31, 2017 at 01:32:47PM +0800, ZhenweiPi wrote:
> ---
> 
>  domain.go      | 13 +++++++++++--
>  domain_test.go | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++---
>  2 files changed, 64 insertions(+), 5 deletions(-)
> 
> diff --git a/domain.go b/domain.go
> index 848835a..cbb22e5 100644
> --- a/domain.go
> +++ b/domain.go
> @@ -30,8 +30,10 @@ import (
>  )
>  type DomainController struct {
> -     Type  string `xml:"type,attr"`
> -     Index string `xml:"index,attr"`
> +     Type    string         `xml:"type,attr"`
> +     Index   *uint          `xml:"index,attr"`
> +     Model   string         `xml:"model,attr,omitempty"`
> +     Address *DomainAddress `xml:"address"`
>  }
>  type DomainDiskSecret struct {
> @@ -77,6 +79,8 @@ type DomainDisk struct {
>       Type     string            `xml:"type,attr"`
>       Device   string            `xml:"device,attr"`
>       Snapshot string            `xml:"snapshot,attr,omitempty"`
> +     Cache    string            `xml:"cache,attr,omitempty"`
> +     Io       string            `xml:"io,attr,omitempty"`
>       Driver   *DomainDiskDriver `xml:"driver"`
>       Auth     *DomainDiskAuth   `xml:"auth"`
>       Source   *DomainDiskSource `xml:"source"`
> @@ -196,8 +200,13 @@ type DomainAlias struct {
>  type DomainAddress struct {
>       Type       string `xml:"type,attr"`
>       Controller *uint  `xml:"controller,attr"`
> +     Domain     *uint  `xml:"domain,attr"`
>       Bus        *uint  `xml:"bus,attr"`
>       Port       *uint  `xml:"port,attr"`
> +     Slot       *uint  `xml:"slot,attr"`
> +     Function   *uint  `xml:"function,attr"`
> +     Target     *uint  `xml:"target,attr"`
> +     Unit       *uint  `xml:"unit,attr"`
>  }
>  type DomainChardev struct {
> diff --git a/domain_test.go b/domain_test.go
> index 265cf80..22da947 100644
> --- a/domain_test.go
> +++ b/domain_test.go
> @@ -30,6 +30,16 @@ import (
>       "testing"
>  )
> +type PciAddress struct {
> +     Domain   uint
> +     Bus      uint
> +     Slot     uint
> +     Function uint
> +}
> +
> +var uhciIndex uint = 0
> +var uhciAddr = PciAddress{0, 0, 1, 2}

This struct and variables are rather pointless - just put the values
inline in the one place where they are needed

> +
>  var domainTestData = []struct {
>       Object   *Domain
>       Expected []string
> @@ -130,10 +140,12 @@ var domainTestData = []struct {
>                                               },
>                                       },
>                                       DomainDisk{
> -                                             Type: "volume",
> +                                             Type:   "volume",
>                                               Device: "cdrom",
> +                                             Cache:  "none",
> +                                             Io:     "native",
>                                               Source: &DomainDiskSource{
> -                                                     Pool: "default",
> +                                                     Pool:   "default",
>                                                       Volume: "myvolume",
>                                               },
>                                               Target: &DomainDiskTarget{
> @@ -174,7 +186,7 @@ var domainTestData = []struct {
>                       `      </source>`,
>                       `      <target dev="vdd" bus="virtio"></target>`,
>                       `    </disk>`,
> -                     `    <disk type="volume" device="cdrom">`,
> +                     `    <disk type="volume" device="cdrom" cache="none" 
> io="native">`,
>                       `      <source pool="default" 
> volume="myvolume"></source>`,
>                       `      <target dev="vde" bus="virtio"></target>`,
>                       `    </disk>`,
> @@ -820,6 +832,44 @@ var domainTestData = []struct {
>                       `</domain>`,
>               },
>       },
> +     {
> +             Object: &Domain{
> +                     Type: "kvm",
> +                     Name: "test",
> +                     Devices: &DomainDeviceList{
> +                             Controllers: []DomainController{
> +                                     DomainController{
> +                                             Type:  "usb",
> +                                             Index: &uhciIndex,
> +                                             Model: "piix3-uhci",
> +                                             Address: &DomainAddress{
> +                                                     Type:     "pci",
> +                                                     Domain:   
> &uhciAddr.Domain,
> +                                                     Bus:      &uhciAddr.Bus,
> +                                                     Slot:     
> &uhciAddr.Slot,
> +                                                     Function: 
> &uhciAddr.Function,
> +                                             },
> +                                     },
> +                                     DomainController{
> +                                             Type:  "usb",
> +                                             Index: nil,
> +                                             Model: "ehci",
> +                                     },
> +                             },
> +                     },
> +             },
> +             Expected: []string{
> +                     `<domain type="kvm">`,
> +                     `  <name>test</name>`,
> +                     `  <devices>`,
> +                     `    <controller type="usb" index="0" 
> model="piix3-uhci">`,
> +                     `      <address type="pci" domain="0" bus="0" slot="1" 
> function="2"></address>`,
> +                     `    </controller>`,
> +                     `    <controller type="usb" model="ehci"></controller>`,
> +                     `  </devices>`,
> +                     `</domain>`,
> +             },
> +     },
>  }
>  func TestDomain(t *testing.T) {
> -- 
> 2.7.4
> 
> 

Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

--
libvir-list mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/libvir-list

Reply via email to