mirror of
https://github.com/LIV2/packer-plugin-vmware.git
synced 2025-12-06 07:02:47 +00:00
Fix issues reported by Go checks (#88)
* Fix go mod tidy check errors * Remove extra spaces to fix goimports error * Fix comments to address reported goimports errors * Convert NetworkMapperMock to pointer receiver The staticcheck error report SA4005: ineffective assignment to field NetworkMapperMock.NameIntoDeviceCalled was valid, as modifying these values would do nothing on the receiver. Converting to a pointer allows for the call to modify the structures data for proper validation. * Fix reported Go linting issues * S1038: should use t.Errorf(...) instead of t.Error(fmt.Sprintf(...)) * SA4001: *&x will be simplified to x. It will not copy x. * File is not `goimports`-ed (goimports)
This commit is contained in:
parent
67b1887a1c
commit
02e7be06a8
@ -215,7 +215,7 @@ func compareVersions(versionFound string, versionWanted string, product string)
|
||||
return nil
|
||||
}
|
||||
|
||||
/// helper functions that read configuration information from a file
|
||||
// helper functions that read configuration information from a file
|
||||
// read the network<->device configuration out of the specified path
|
||||
func ReadNetmapConfig(path string) (NetworkMap, error) {
|
||||
fd, err := os.Open(path)
|
||||
|
||||
@ -54,7 +54,7 @@ func TestESX5Driver_HostIP(t *testing.T) {
|
||||
state := new(multistep.BasicStateBag)
|
||||
|
||||
if host, _ := driver.HostIP(state); host != expected_host {
|
||||
t.Error(fmt.Sprintf("Expected string, %s but got %s", expected_host, host))
|
||||
t.Errorf("Expected string, %s but got %s", expected_host, host)
|
||||
}
|
||||
}
|
||||
|
||||
@ -75,7 +75,7 @@ func TestESX5Driver_CommHost(t *testing.T) {
|
||||
state := new(multistep.BasicStateBag)
|
||||
sshConfig := SSHConfig{Comm: commConfig}
|
||||
state.Put("sshConfig", &sshConfig)
|
||||
driver := ESX5Driver{CommConfig: *(&sshConfig.Comm)}
|
||||
driver := ESX5Driver{CommConfig: sshConfig.Comm}
|
||||
|
||||
host, err := driver.CommHost(state)
|
||||
if err != nil {
|
||||
|
||||
@ -110,11 +110,11 @@ type NetworkMapperMock struct {
|
||||
DeviceIntoNameCalled int
|
||||
}
|
||||
|
||||
func (m NetworkMapperMock) NameIntoDevices(name string) ([]string, error) {
|
||||
func (m *NetworkMapperMock) NameIntoDevices(name string) ([]string, error) {
|
||||
m.NameIntoDeviceCalled += 1
|
||||
return make([]string, 0), nil
|
||||
}
|
||||
func (m NetworkMapperMock) DeviceIntoName(device string) (string, error) {
|
||||
func (m *NetworkMapperMock) DeviceIntoName(device string) (string, error) {
|
||||
m.DeviceIntoNameCalled += 1
|
||||
return "", nil
|
||||
}
|
||||
@ -291,7 +291,7 @@ func (d *DriverMock) GetVmwareDriver() VmwareDriver {
|
||||
return "/path/to/vmnetnat.conf"
|
||||
}
|
||||
state.NetworkMapper = func() (NetworkNameMapper, error) {
|
||||
return NetworkMapperMock{}, nil
|
||||
return &NetworkMapperMock{}, nil
|
||||
}
|
||||
return state
|
||||
}
|
||||
|
||||
@ -610,7 +610,7 @@ func (e *pDeclaration) repr() string {
|
||||
|
||||
type pDeclarationGlobal struct{}
|
||||
|
||||
func (e pDeclarationGlobal) repr() string { return fmt.Sprintf("{global}") }
|
||||
func (e pDeclarationGlobal) repr() string { return "{global}" }
|
||||
|
||||
type pDeclarationShared struct{ name string }
|
||||
|
||||
@ -630,11 +630,11 @@ func (e pDeclarationHost) repr() string { return fmt.Sprintf("{host name:%s}", e
|
||||
|
||||
type pDeclarationPool struct{}
|
||||
|
||||
func (e pDeclarationPool) repr() string { return fmt.Sprintf("{pool}") }
|
||||
func (e pDeclarationPool) repr() string { return "{pool}" }
|
||||
|
||||
type pDeclarationGroup struct{}
|
||||
|
||||
func (e pDeclarationGroup) repr() string { return fmt.Sprintf("{group}") }
|
||||
func (e pDeclarationGroup) repr() string { return "{group}" }
|
||||
|
||||
/** parsers */
|
||||
func parseParameter(val tkParameter) (pParameter, error) {
|
||||
@ -1360,7 +1360,7 @@ func splitNetworkingConfig(in chan string) chan []string {
|
||||
return out
|
||||
}
|
||||
|
||||
/// All token types in networking file.
|
||||
// All token types in networking file.
|
||||
// VERSION token
|
||||
type networkingVERSION struct {
|
||||
value string
|
||||
@ -2198,13 +2198,10 @@ func filterOutCharacters(ignore []byte, in chan byte) chan byte {
|
||||
return out
|
||||
}
|
||||
|
||||
/**
|
||||
This consumes bytes within a pair of some bytes, like parentheses, brackets, braces...
|
||||
|
||||
We start by reading bytes until we encounter openByte. These will be returned as
|
||||
the first parameter. Then we can enter a goro and consume bytes until we get to
|
||||
closeByte. At that point we're done, and we can exit.
|
||||
**/
|
||||
// consumeOpenClosePair consumes bytes within a pair of some bytes, like parentheses, brackets, braces.
|
||||
// We start by reading bytes until we encounter openByte. These will be returned as
|
||||
// the first parameter. Then we can enter a goro and consume bytes until we get to
|
||||
// closeByte. At that point we're done, and we can exit.
|
||||
func consumeOpenClosePair(openByte, closeByte byte, in chan byte) ([]byte, chan byte) {
|
||||
result := make([]byte, 0)
|
||||
|
||||
|
||||
@ -18,11 +18,11 @@ var KeepFileExtensions = []string{".nvram", ".vmdk", ".vmsd", ".vmx", ".vmxf"}
|
||||
// This step removes unnecessary files from the final result.
|
||||
//
|
||||
// Uses:
|
||||
// dir OutputDir
|
||||
// ui packersdk.Ui
|
||||
// dir OutputDir
|
||||
// ui packersdk.Ui
|
||||
//
|
||||
// Produces:
|
||||
// <nothing>
|
||||
// <nothing>
|
||||
type StepCleanFiles struct{}
|
||||
|
||||
func (StepCleanFiles) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
|
||||
|
||||
@ -10,15 +10,8 @@ import (
|
||||
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
|
||||
)
|
||||
|
||||
// This step cleans up the VMX by removing or changing this prior to
|
||||
// StepCleanVMX cleans up the VMX by removing or changing this prior to
|
||||
// being ready for use.
|
||||
//
|
||||
// Uses:
|
||||
// ui packersdk.Ui
|
||||
// vmx_path string
|
||||
//
|
||||
// Produces:
|
||||
// <nothing>
|
||||
type StepCleanVMX struct {
|
||||
RemoveEthernetInterfaces bool
|
||||
VNCEnabled bool
|
||||
|
||||
@ -13,12 +13,12 @@ import (
|
||||
// boolean is true.
|
||||
//
|
||||
// Uses:
|
||||
// driver Driver
|
||||
// disk_full_paths ([]string) - The full paths to all created disks
|
||||
// ui packersdk.Ui
|
||||
// driver Driver
|
||||
// disk_full_paths ([]string) - The full paths to all created disks
|
||||
// ui packersdk.Ui
|
||||
//
|
||||
// Produces:
|
||||
// <nothing>
|
||||
// <nothing>
|
||||
type StepCompactDisk struct {
|
||||
Skip bool
|
||||
}
|
||||
|
||||
@ -14,11 +14,8 @@ import (
|
||||
// This step configures a VMX by setting some default settings as well
|
||||
// as taking in custom data to set, attaching a floppy if it exists, etc.
|
||||
//
|
||||
// Uses:
|
||||
// vmx_path string
|
||||
//
|
||||
// Produces:
|
||||
// display_name string - Value of the displayName key set in the VMX file
|
||||
// Uses: vmx_path string
|
||||
// Produces: display_name string - Value of the displayName key set in the VMX file
|
||||
type StepConfigureVMX struct {
|
||||
CustomData map[string]string
|
||||
DisplayName string
|
||||
|
||||
@ -14,11 +14,12 @@ import (
|
||||
// This step configures the VM to enable the VNC server.
|
||||
//
|
||||
// Uses:
|
||||
// ui packersdk.Ui
|
||||
// vmx_path string
|
||||
// ui packersdk.Ui
|
||||
// vmx_path string
|
||||
//
|
||||
// Produces:
|
||||
// vnc_port int - The port that VNC is configured to listen on.
|
||||
// vnc_port int - The port that VNC is configured to listen on.
|
||||
|
||||
type StepConfigureVNC struct {
|
||||
Enabled bool
|
||||
VNCBindAddress string
|
||||
|
||||
@ -10,15 +10,7 @@ import (
|
||||
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
|
||||
)
|
||||
|
||||
// This step creates the virtual disks for the VM.
|
||||
//
|
||||
// Uses:
|
||||
// config *config
|
||||
// driver Driver
|
||||
// ui packersdk.Ui
|
||||
//
|
||||
// Produces:
|
||||
// disk_full_paths ([]string) - The full paths to all created disks
|
||||
// StepCreateDisks creates the virtual disks for the VM.
|
||||
type StepCreateDisks struct {
|
||||
OutputDir *string
|
||||
CreateMainDisk bool
|
||||
|
||||
@ -8,15 +8,7 @@ import (
|
||||
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
|
||||
)
|
||||
|
||||
// This step creates the intial snapshot for the VM after clean-up.
|
||||
//
|
||||
// Uses:
|
||||
// config *config
|
||||
// driver Driver
|
||||
// ui packersdk.Ui
|
||||
//
|
||||
// Produces:
|
||||
// snapshot
|
||||
// StepCreateSnapshot step creates the intial snapshot for the VM after clean-up.
|
||||
type StepCreateSnapshot struct {
|
||||
SnapshotName *string
|
||||
}
|
||||
|
||||
@ -9,15 +9,7 @@ import (
|
||||
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
|
||||
)
|
||||
|
||||
// This step runs the created virtual machine.
|
||||
//
|
||||
// Uses:
|
||||
// driver Driver
|
||||
// ui packersdk.Ui
|
||||
// vmx_path string
|
||||
//
|
||||
// Produces:
|
||||
// <nothing>
|
||||
// StepRun runs the created virtual machine.
|
||||
type StepRun struct {
|
||||
DurationBeforeStop time.Duration
|
||||
Headless bool
|
||||
|
||||
@ -14,18 +14,8 @@ import (
|
||||
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
|
||||
)
|
||||
|
||||
// This step shuts down the machine. It first attempts to do so gracefully,
|
||||
// StepShutdown shuts down the machine. It first attempts to do so gracefully,
|
||||
// but ultimately forcefully shuts it down if that fails.
|
||||
//
|
||||
// Uses:
|
||||
// communicator packersdk.Communicator
|
||||
// dir OutputDir
|
||||
// driver Driver
|
||||
// ui packersdk.Ui
|
||||
// vmx_path string
|
||||
//
|
||||
// Produces:
|
||||
// <nothing>
|
||||
type StepShutdown struct {
|
||||
Command string
|
||||
Timeout time.Duration
|
||||
|
||||
@ -9,15 +9,7 @@ import (
|
||||
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
|
||||
)
|
||||
|
||||
// This step upload the VMX to the remote host
|
||||
//
|
||||
// Uses:
|
||||
// driver Driver
|
||||
// ui packersdk.Ui
|
||||
// vmx_path string
|
||||
//
|
||||
// Produces:
|
||||
// <nothing>
|
||||
// StepUploadVMX upload the VMX to the remote host
|
||||
type StepUploadVMX struct {
|
||||
RemoteType string
|
||||
}
|
||||
|
||||
@ -13,15 +13,7 @@ import (
|
||||
"github.com/mitchellh/go-vnc"
|
||||
)
|
||||
|
||||
// This step "types" the boot command into the VM over VNC.
|
||||
//
|
||||
// Uses:
|
||||
// http_port int
|
||||
// ui packersdk.Ui
|
||||
// vnc_port int
|
||||
//
|
||||
// Produces:
|
||||
// <nothing>
|
||||
// StepVNCBootCommand "types" the boot command into the VM over VNC.
|
||||
type StepVNCBootCommand struct {
|
||||
Config bootcommand.VNCConfig
|
||||
VMName string
|
||||
|
||||
@ -56,14 +56,6 @@ type additionalDiskTemplateData struct {
|
||||
}
|
||||
|
||||
// This step creates the VMX file for the VM.
|
||||
//
|
||||
// Uses:
|
||||
// config *config
|
||||
// iso_path string
|
||||
// ui packersdk.Ui
|
||||
//
|
||||
// Produces:
|
||||
// vmx_path string - The path to the VMX file.
|
||||
type stepCreateVMX struct {
|
||||
tempDir string
|
||||
}
|
||||
|
||||
1
go.mod
1
go.mod
@ -91,5 +91,6 @@ require (
|
||||
google.golang.org/grpc v1.40.0 // indirect
|
||||
google.golang.org/protobuf v1.27.1 // indirect
|
||||
gopkg.in/square/go-jose.v2 v2.6.0 // indirect
|
||||
gopkg.in/yaml.v2 v2.3.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
|
||||
)
|
||||
|
||||
1
go.sum
1
go.sum
@ -999,7 +999,6 @@ gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
|
||||
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
|
||||
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user