diff options
author | Dario Maiocchi <dmaiocchi@suse.com> | 2017-11-12 19:50:51 +0100 |
---|---|---|
committer | Dario Maiocchi <dmaiocchi@suse.com> | 2017-11-16 15:11:04 +0100 |
commit | 3a4cd93e91aad054f89491e9f91fba6cf92dbc19 (patch) | |
tree | 286d4f3913968f3706b0f286c76b6c08a8e5c611 | |
parent | 1205df84cacd81887839c31572952dc21065da77 (diff) | |
download | terraform-provider-libvirt-3a4cd93e91aad054f89491e9f91fba6cf92dbc19.tar terraform-provider-libvirt-3a4cd93e91aad054f89491e9f91fba6cf92dbc19.tar.gz |
golint on resource_libvirt_domain_test.go
Use correct names in comments
-rw-r--r-- | libvirt/cloudinit_def.go | 4 | ||||
-rw-r--r-- | libvirt/libvirt_interfaces.go | 4 | ||||
-rw-r--r-- | libvirt/network_def.go | 2 | ||||
-rw-r--r-- | libvirt/pool_sync.go | 6 | ||||
-rw-r--r-- | libvirt/resource_libvirt_domain.go | 1 | ||||
-rw-r--r-- | libvirt/resource_libvirt_domain_test.go | 58 | ||||
-rw-r--r-- | libvirt/stream.go | 6 | ||||
-rw-r--r-- | libvirt/utils.go | 2 | ||||
-rw-r--r-- | libvirt/utils_net.go | 8 |
9 files changed, 58 insertions, 33 deletions
diff --git a/libvirt/cloudinit_def.go b/libvirt/cloudinit_def.go index 59ccbb63..fb148b75 100644 --- a/libvirt/cloudinit_def.go +++ b/libvirt/cloudinit_def.go @@ -19,10 +19,10 @@ import ( "gopkg.in/yaml.v2" ) -// USERDATA is the name of file expected by cloud-init +// USERDATA is the filename expected by cloud-init const USERDATA string = "user-data" -// METADATA is the name of file expected by cloud-init +// METADATA is the filename expected by cloud-init const METADATA string = "meta-data" // CloudInitUserData struct diff --git a/libvirt/libvirt_interfaces.go b/libvirt/libvirt_interfaces.go index 36161dc3..5623cde2 100644 --- a/libvirt/libvirt_interfaces.go +++ b/libvirt/libvirt_interfaces.go @@ -2,13 +2,13 @@ package libvirt import "github.com/libvirt/libvirt-go" -// Domain Interface used to expose a libvirt.Domain +// Domain Interface used to expose a libvirt.Domain // Used to allow testing type Domain interface { QemuAgentCommand(command string, timeout libvirt.DomainQemuAgentCommandTimeout, flags uint32) (string, error) } -// Network interface +// Network interface used to expose a libvirt.Network type Network interface { GetXMLDesc(flags libvirt.NetworkXMLFlags) (string, error) } diff --git a/libvirt/network_def.go b/libvirt/network_def.go index 66e17127..77ead849 100644 --- a/libvirt/network_def.go +++ b/libvirt/network_def.go @@ -7,7 +7,7 @@ import ( "github.com/libvirt/libvirt-go-xml" ) -// HasDHCP Check if the network has a DHCP server managed by libvirt +// HasDHCP checks if the network has a DHCP server managed by libvirt func HasDHCP(net libvirtxml.Network) bool { if net.Forward != nil { if net.Forward.Mode == "nat" || net.Forward.Mode == "route" || net.Forward.Mode == "" { diff --git a/libvirt/pool_sync.go b/libvirt/pool_sync.go index f99af77e..a50528bc 100644 --- a/libvirt/pool_sync.go +++ b/libvirt/pool_sync.go @@ -13,7 +13,7 @@ type LVirtPoolSync struct { internalMutex sync.Mutex } -// NewLVirtPoolSync Allocate a new instance of LVirtPoolSync +// NewLVirtPoolSync allocates a new instance of LVirtPoolSync func NewLVirtPoolSync() LVirtPoolSync { pool := LVirtPoolSync{} pool.PoolLocks = make(map[string]*sync.Mutex) @@ -21,7 +21,7 @@ func NewLVirtPoolSync() LVirtPoolSync { return pool } -// AcquireLock Acquire a lock for the specified pool +// AcquireLock acquires a lock for the specified pool func (ps LVirtPoolSync) AcquireLock(pool string) { ps.internalMutex.Lock() defer ps.internalMutex.Unlock() @@ -35,7 +35,7 @@ func (ps LVirtPoolSync) AcquireLock(pool string) { lock.Lock() } -// ReleaseLock Release the look for the specified pool +// ReleaseLock releases the look for the specified pool func (ps LVirtPoolSync) ReleaseLock(pool string) { ps.internalMutex.Lock() defer ps.internalMutex.Unlock() diff --git a/libvirt/resource_libvirt_domain.go b/libvirt/resource_libvirt_domain.go index 652bc17e..317bfd33 100644 --- a/libvirt/resource_libvirt_domain.go +++ b/libvirt/resource_libvirt_domain.go @@ -226,7 +226,6 @@ func resourceLibvirtDomainCreate(d *schema.ResourceData, meta interface{}) error } if ignition, ok := d.GetOk("coreos_ignition"); ok { - //var fwCfg []defCmd var fwCfg []libvirtxml.DomainQEMUCommandlineArg ignitionKey, err := getIgnitionVolumeKeyFromTerraformID(ignition.(string)) if err != nil { diff --git a/libvirt/resource_libvirt_domain_test.go b/libvirt/resource_libvirt_domain_test.go index 368ed2c2..954f1ba5 100644 --- a/libvirt/resource_libvirt_domain_test.go +++ b/libvirt/resource_libvirt_domain_test.go @@ -5,6 +5,7 @@ import ( "fmt" "io/ioutil" "log" + "os" "testing" "github.com/hashicorp/terraform/helper/resource" @@ -591,13 +592,13 @@ func testAccCheckLibvirtScsiDisk(n string, domain *libvirt.Domain) resource.Test func createNvramFile() (string, error) { // size of an accepted, valid, nvram backing store - nvramDummyBuffer := make([]byte, 131072) + NVRAMDummyBuffer := make([]byte, 131072) file, err := ioutil.TempFile("/tmp", "nvram") if err != nil { return "", err } file.Chmod(0777) - _, err = file.Write(nvramDummyBuffer) + _, err = file.Write(NVRAMDummyBuffer) if err != nil { return "", err } @@ -607,21 +608,46 @@ func createNvramFile() (string, error) { return file.Name(), nil } -func TestAccLibvirtDomain_FirmwareNoTemplate(t *testing.T) { - nvramPath, err := createNvramFile() +func TestAccLibvirtDomainFirmware(t *testing.T) { + NVRAMPath, err := createNvramFile() if err != nil { t.Fatal(err) } + firmware := fmt.Sprintf("/usr/share/qemu/ovmf-x86_64-code.bin") + if _, err := os.Stat(firmware); os.IsNotExist(err) { + firmware = "/usr/share/ovmf/OVMF.fd" + if _, err := os.Stat(firmware); os.IsNotExist(err) { + t.Skip("Can't test domain custom firmware: OVMF firmware not found: %s") + } + } + + template := fmt.Sprintf("/usr/share/qemu/ovmf-x86_64-vars.bin") + if _, err := os.Stat(template); os.IsNotExist(err) { + template = "/usr/share/qemu/OVMF.fd" + if _, err := os.Stat(template); os.IsNotExist(err) { + t.Skip("Can't test domain custom firmware template: OVMF template not found: %s") + } + } + + t.Run("No Template", func(t *testing.T) { + subtestAccLibvirtDomainFirmwareNoTemplate(t, NVRAMPath, firmware) + }) + t.Run("With Template", func(t *testing.T) { + subtestAccLibvirtDomainFirmwareTemplate(t, NVRAMPath, firmware, template) + }) +} + +func subtestAccLibvirtDomainFirmwareNoTemplate(t *testing.T, NVRAMPath string, firmware string) { var domain libvirt.Domain var config = fmt.Sprintf(` resource "libvirt_domain" "acceptance-test-domain" { name = "terraform-test-firmware-no-template" - firmware = "/usr/share/ovmf/OVMF.fd" + firmware = "%s" nvram { file = "%s" } - }`, nvramPath) + }`, firmware, NVRAMPath) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -635,17 +661,17 @@ func TestAccLibvirtDomain_FirmwareNoTemplate(t *testing.T) { resource.TestCheckResourceAttr( "libvirt_domain.acceptance-test-domain", "name", "terraform-test-firmware-no-template"), resource.TestCheckResourceAttr( - "libvirt_domain.acceptance-test-domain", "nvram.file", nvramPath), + "libvirt_domain.acceptance-test-domain", "nvram.file", NVRAMPath), resource.TestCheckResourceAttr( - "libvirt_domain.acceptance-test-domain", "firmware", "/usr/share/ovmf/OVMF.fd"), + "libvirt_domain.acceptance-test-domain", "firmware", firmware), ), }, }, }) } -func TestAccLibvirtDomain_FirmwareTemplate(t *testing.T) { - nvramPath, err := createNvramFile() +func subtestAccLibvirtDomainFirmwareTemplate(t *testing.T, NVRAMPath string, firmware string, template string) { + NVRAMPath, err := createNvramFile() if err != nil { t.Fatal(err) } @@ -654,12 +680,12 @@ func TestAccLibvirtDomain_FirmwareTemplate(t *testing.T) { var config = fmt.Sprintf(` resource "libvirt_domain" "acceptance-test-domain" { name = "terraform-test-firmware-with-template" - firmware = "/usr/share/ovmf/OVMF.fd" + firmware = "%s" nvram { file = "%s" - template = "/usr/share/qemu/OVMF.fd" + template = "%s" } - }`, nvramPath) + }`, firmware, NVRAMPath, template) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -673,11 +699,11 @@ func TestAccLibvirtDomain_FirmwareTemplate(t *testing.T) { resource.TestCheckResourceAttr( "libvirt_domain.acceptance-test-domain", "name", "terraform-test-firmware-with-template"), resource.TestCheckResourceAttr( - "libvirt_domain.acceptance-test-domain", "nvram.file", nvramPath), + "libvirt_domain.acceptance-test-domain", "nvram.file", NVRAMPath), resource.TestCheckResourceAttr( - "libvirt_domain.acceptance-test-domain", "nvram.template", "/usr/share/qemu/OVMF.fd"), + "libvirt_domain.acceptance-test-domain", "nvram.template", template), resource.TestCheckResourceAttr( - "libvirt_domain.acceptance-test-domain", "firmware", "/usr/share/ovmf/OVMF.fd"), + "libvirt_domain.acceptance-test-domain", "firmware", firmware), ), }, }, diff --git a/libvirt/stream.go b/libvirt/stream.go index 1c5a24e9..4223466c 100644 --- a/libvirt/stream.go +++ b/libvirt/stream.go @@ -2,12 +2,12 @@ package libvirt import libvirt "github.com/libvirt/libvirt-go" -// StreamIO struct +// StreamIO libvirt struct type StreamIO struct { Stream libvirt.Stream } -// NewStreamIO return libvirt StreamIO +// NewStreamIO returns libvirt StreamIO func NewStreamIO(s libvirt.Stream) *StreamIO { return &StreamIO{Stream: s} } @@ -20,7 +20,7 @@ func (sio *StreamIO) Write(p []byte) (int, error) { return sio.Stream.Send(p) } -// Close StreamIO +// Close closes the stream func (sio *StreamIO) Close() error { return sio.Stream.Finish() } diff --git a/libvirt/utils.go b/libvirt/utils.go index d043051c..a82417fb 100644 --- a/libvirt/utils.go +++ b/libvirt/utils.go @@ -64,7 +64,7 @@ func xmlMarshallIndented(b interface{}) (string, error) { return buf.String(), nil } -// RemoveVolume Remove the volume identified by `key` from libvirt +// RemoveVolume removes the volume identified by `key` from libvirt func RemoveVolume(virConn *libvirt.Connect, key string) error { volume, err := virConn.LookupStorageVolByKey(key) if err != nil { diff --git a/libvirt/utils_net.go b/libvirt/utils_net.go index a769d806..140c4a8d 100644 --- a/libvirt/utils_net.go +++ b/libvirt/utils_net.go @@ -15,7 +15,7 @@ const ( maxIfaceNum = 100 ) -// RandomMACAddress mac random +// RandomMACAddress returns a randomized MAC address func RandomMACAddress() (string, error) { buf := make([]byte, 6) _, err := rand.Read(buf) @@ -37,7 +37,7 @@ func RandomMACAddress() (string, error) { buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]), nil } -// RandomPort return randomport +// RandomPort returns a random port func RandomPort() int { const minPort = 1024 const maxPort = 65535 @@ -46,7 +46,7 @@ func RandomPort() int { return rand.Intn(maxPort-minPort) + minPort } -// FreeNetworkInterface free network interface +// FreeNetworkInterface returns a free network interface func FreeNetworkInterface(basename string) (string, error) { for i := 0; i < maxIfaceNum; i++ { ifaceName := fmt.Sprintf("%s%d", basename, i) @@ -58,7 +58,7 @@ func FreeNetworkInterface(basename string) (string, error) { return "", fmt.Errorf("could not obtain a free network interface") } -// NetworkRange Calculates the first and last IP addresses in an IPNet +// NetworkRange calculates the first and last IP addresses in an IPNet func NetworkRange(network *net.IPNet) (net.IP, net.IP) { netIP := network.IP.To4() lastIP := net.IPv4(0, 0, 0, 0).To4() |