diff --git a/Makefile b/Makefile index c49e005c8..622fed1df 100644 --- a/Makefile +++ b/Makefile @@ -53,7 +53,7 @@ fmt-examples: # source files. generate: deps ## Generate dynamically generated code go generate . - go fmt command/plugin.go + gofmt -w command/plugin.go test: deps ## Run unit tests @go test $(TEST) $(TESTARGS) -timeout=2m diff --git a/builder/googlecompute/artifact.go b/builder/googlecompute/artifact.go index 7738daa50..9d98d6566 100644 --- a/builder/googlecompute/artifact.go +++ b/builder/googlecompute/artifact.go @@ -41,16 +41,16 @@ func (a *Artifact) String() string { func (a *Artifact) State(name string) interface{} { switch name { - case "ImageName": - return a.image.Name - case "ImageSizeGb": - return a.image.SizeGb - case "AccountFilePath": - return a.config.AccountFile - case "ProjectId": - return a.config.ProjectId - case "BuildZone": - return a.config.Zone + case "ImageName": + return a.image.Name + case "ImageSizeGb": + return a.image.SizeGb + case "AccountFilePath": + return a.config.AccountFile + case "ProjectId": + return a.config.ProjectId + case "BuildZone": + return a.config.Zone } return nil } diff --git a/builder/googlecompute/driver.go b/builder/googlecompute/driver.go index 183ef294d..5a9a89dfb 100644 --- a/builder/googlecompute/driver.go +++ b/builder/googlecompute/driver.go @@ -31,7 +31,7 @@ type Driver interface { // GetNatIP gets the NAT IP address for the instance. GetNatIP(zone, name string) (string, error) - + // GetSerialPortOutput gets the Serial Port contents for the instance. GetSerialPortOutput(zone, name string) (string, error) diff --git a/builder/googlecompute/driver_mock.go b/builder/googlecompute/driver_mock.go index b911aa6d6..f44f6c475 100644 --- a/builder/googlecompute/driver_mock.go +++ b/builder/googlecompute/driver_mock.go @@ -54,7 +54,7 @@ type DriverMock struct { GetInternalIPName string GetInternalIPResult string GetInternalIPErr error - + GetSerialPortOutputZone string GetSerialPortOutputName string GetSerialPortOutputResult string diff --git a/builder/googlecompute/image_test.go b/builder/googlecompute/image_test.go index 10998a1de..d6ac8e99f 100644 --- a/builder/googlecompute/image_test.go +++ b/builder/googlecompute/image_test.go @@ -1,19 +1,19 @@ package googlecompute -import( - "testing" +import ( "fmt" + "testing" "github.com/stretchr/testify/assert" ) func StubImage(name, project string, licenses []string, sizeGb int64) *Image { return &Image{ - Licenses: licenses, - Name: name, + Licenses: licenses, + Name: name, ProjectId: project, - SelfLink: fmt.Sprintf("https://www.googleapis.com/compute/v1/projects/%s/global/images/%s", project, name), - SizeGb: sizeGb, + SelfLink: fmt.Sprintf("https://www.googleapis.com/compute/v1/projects/%s/global/images/%s", project, name), + SizeGb: sizeGb, } } diff --git a/builder/googlecompute/step_create_image_test.go b/builder/googlecompute/step_create_image_test.go index 0b5a096d3..63c962904 100644 --- a/builder/googlecompute/step_create_image_test.go +++ b/builder/googlecompute/step_create_image_test.go @@ -28,12 +28,12 @@ func TestStepCreateImage(t *testing.T) { // run the step action := step.Run(state) assert.Equal(t, action, multistep.ActionContinue, "Step did not pass.") - + uncastImage, ok := state.GetOk("image") assert.True(t, ok, "State does not have resulting image.") image, ok := uncastImage.(*Image) assert.True(t, ok, "Image in state is not an Image.") - + // Verify created Image results. assert.Equal(t, image.Licenses, d.CreateImageResultLicenses, "Created image licenses don't match the licenses returned by the driver.") assert.Equal(t, image.Name, c.ImageName, "Created image does not match config name.") diff --git a/builder/googlecompute/step_create_instance.go b/builder/googlecompute/step_create_instance.go index f3844ef67..ba978b47d 100644 --- a/builder/googlecompute/step_create_instance.go +++ b/builder/googlecompute/step_create_instance.go @@ -31,7 +31,7 @@ func (c *Config) createInstanceMetadata(sourceImage *Image, sshPublicKey string) sshKeys = fmt.Sprintf("%s\n%s", sshKeys, confSshKeys) } instanceMetadata[sshMetaKey] = sshKeys - + // Wrap any startup script with our own startup script. if c.StartupScriptFile != "" { var content []byte diff --git a/builder/googlecompute/step_teardown_instance.go b/builder/googlecompute/step_teardown_instance.go index 1af2be8a4..9f998a059 100644 --- a/builder/googlecompute/step_teardown_instance.go +++ b/builder/googlecompute/step_teardown_instance.go @@ -71,8 +71,8 @@ func (s *StepTeardownInstance) Cleanup(state multistep.StateBag) { if err != nil { ui.Error(fmt.Sprintf( "Error deleting disk. Please delete it manually.\n\n"+ - "DiskName: %s\n" + - "Zone: %s\n" + + "DiskName: %s\n"+ + "Zone: %s\n"+ "Error: %s", config.DiskName, config.Zone, err)) } diff --git a/builder/googlecompute/step_wait_instance_startup_test.go b/builder/googlecompute/step_wait_instance_startup_test.go index 1013a10df..404fd8012 100644 --- a/builder/googlecompute/step_wait_instance_startup_test.go +++ b/builder/googlecompute/step_wait_instance_startup_test.go @@ -2,8 +2,8 @@ package googlecompute import ( "github.com/mitchellh/multistep" - "testing" "github.com/stretchr/testify/assert" + "testing" ) func TestStepWaitInstanceStartup(t *testing.T) { @@ -11,7 +11,7 @@ func TestStepWaitInstanceStartup(t *testing.T) { step := new(StepWaitInstanceStartup) c := state.Get("config").(*Config) d := state.Get("driver").(*DriverMock) - + testZone := "test-zone" testInstanceName := "test-instance-name" @@ -20,11 +20,11 @@ func TestStepWaitInstanceStartup(t *testing.T) { // This step stops when it gets Done back from the metadata. d.GetInstanceMetadataResult = StartupScriptStatusDone - + // Run the step. assert.Equal(t, step.Run(state), multistep.ActionContinue, "Step should have passed and continued.") - + // Check that GetInstanceMetadata was called properly. assert.Equal(t, d.GetInstanceMetadataZone, testZone, "Incorrect zone passed to GetInstanceMetadata.") assert.Equal(t, d.GetInstanceMetadataName, testInstanceName, "Incorrect instance name passed to GetInstanceMetadata.") -} \ No newline at end of file +} diff --git a/builder/vmware/common/vmx.go b/builder/vmware/common/vmx.go index e531e4341..1735bfb53 100755 --- a/builder/vmware/common/vmx.go +++ b/builder/vmware/common/vmx.go @@ -46,13 +46,13 @@ func EncodeVMX(contents map[string]string) string { // a list of VMX key fragments that the value must not be quoted // fragments are used to cover multliples (i.e. multiple disks) // keys are still lowercase at this point, use lower fragments - noQuotes := []string { + noQuotes := []string{ ".virtualssd", } // a list of VMX key fragments that are case sensitive // fragments are used to cover multliples (i.e. multiple disks) - caseSensitive := []string { + caseSensitive := []string{ ".virtualSSD", } @@ -63,7 +63,7 @@ func EncodeVMX(contents map[string]string) string { for _, q := range noQuotes { if strings.Contains(k, q) { pat = "%s = %s\n" - break; + break } } key := k diff --git a/builder/vmware/common/vmx_test.go b/builder/vmware/common/vmx_test.go index 715a6a6ee..967f01259 100755 --- a/builder/vmware/common/vmx_test.go +++ b/builder/vmware/common/vmx_test.go @@ -29,8 +29,8 @@ scsi0:0.virtualSSD = 1 func TestEncodeVMX(t *testing.T) { contents := map[string]string{ - ".encoding": "UTF-8", - "config.version": "8", + ".encoding": "UTF-8", + "config.version": "8", "scsi0:0.virtualssd": "1", } diff --git a/command/plugin.go b/command/plugin.go index 4def4582b..3c6715f9a 100644 --- a/command/plugin.go +++ b/command/plugin.go @@ -15,50 +15,49 @@ import ( amazonchrootbuilder "github.com/mitchellh/packer/builder/amazon/chroot" amazonebsbuilder "github.com/mitchellh/packer/builder/amazon/ebs" - amazonimportpostprocessor "github.com/mitchellh/packer/post-processor/amazon-import" amazoninstancebuilder "github.com/mitchellh/packer/builder/amazon/instance" - ansiblelocalprovisioner "github.com/mitchellh/packer/provisioner/ansible-local" - ansibleprovisioner "github.com/mitchellh/packer/provisioner/ansible" - artificepostprocessor "github.com/mitchellh/packer/post-processor/artifice" - atlaspostprocessor "github.com/mitchellh/packer/post-processor/atlas" azurearmbuilder "github.com/mitchellh/packer/builder/azure/arm" - checksumpostprocessor "github.com/mitchellh/packer/post-processor/checksum" - chefclientprovisioner "github.com/mitchellh/packer/provisioner/chef-client" - chefsoloprovisioner "github.com/mitchellh/packer/provisioner/chef-solo" - compresspostprocessor "github.com/mitchellh/packer/post-processor/compress" digitaloceanbuilder "github.com/mitchellh/packer/builder/digitalocean" dockerbuilder "github.com/mitchellh/packer/builder/docker" - dockerimportpostprocessor "github.com/mitchellh/packer/post-processor/docker-import" - dockerpushpostprocessor "github.com/mitchellh/packer/post-processor/docker-push" - dockersavepostprocessor "github.com/mitchellh/packer/post-processor/docker-save" - dockertagpostprocessor "github.com/mitchellh/packer/post-processor/docker-tag" filebuilder "github.com/mitchellh/packer/builder/file" - fileprovisioner "github.com/mitchellh/packer/provisioner/file" googlecomputebuilder "github.com/mitchellh/packer/builder/googlecompute" - googlecomputeexportpostprocessor "github.com/mitchellh/packer/post-processor/googlecompute-export" - manifestpostprocessor "github.com/mitchellh/packer/post-processor/manifest" nullbuilder "github.com/mitchellh/packer/builder/null" openstackbuilder "github.com/mitchellh/packer/builder/openstack" parallelsisobuilder "github.com/mitchellh/packer/builder/parallels/iso" parallelspvmbuilder "github.com/mitchellh/packer/builder/parallels/pvm" - powershellprovisioner "github.com/mitchellh/packer/provisioner/powershell" - puppetmasterlessprovisioner "github.com/mitchellh/packer/provisioner/puppet-masterless" - puppetserverprovisioner "github.com/mitchellh/packer/provisioner/puppet-server" qemubuilder "github.com/mitchellh/packer/builder/qemu" - saltmasterlessprovisioner "github.com/mitchellh/packer/provisioner/salt-masterless" - shelllocalpostprocessor "github.com/mitchellh/packer/post-processor/shell-local" - shelllocalprovisioner "github.com/mitchellh/packer/provisioner/shell-local" - shellprovisioner "github.com/mitchellh/packer/provisioner/shell" - vagrantcloudpostprocessor "github.com/mitchellh/packer/post-processor/vagrant-cloud" - vagrantpostprocessor "github.com/mitchellh/packer/post-processor/vagrant" virtualboxisobuilder "github.com/mitchellh/packer/builder/virtualbox/iso" virtualboxovfbuilder "github.com/mitchellh/packer/builder/virtualbox/ovf" vmwareisobuilder "github.com/mitchellh/packer/builder/vmware/iso" vmwarevmxbuilder "github.com/mitchellh/packer/builder/vmware/vmx" + amazonimportpostprocessor "github.com/mitchellh/packer/post-processor/amazon-import" + artificepostprocessor "github.com/mitchellh/packer/post-processor/artifice" + atlaspostprocessor "github.com/mitchellh/packer/post-processor/atlas" + checksumpostprocessor "github.com/mitchellh/packer/post-processor/checksum" + compresspostprocessor "github.com/mitchellh/packer/post-processor/compress" + dockerimportpostprocessor "github.com/mitchellh/packer/post-processor/docker-import" + dockerpushpostprocessor "github.com/mitchellh/packer/post-processor/docker-push" + dockersavepostprocessor "github.com/mitchellh/packer/post-processor/docker-save" + dockertagpostprocessor "github.com/mitchellh/packer/post-processor/docker-tag" + googlecomputeexportpostprocessor "github.com/mitchellh/packer/post-processor/googlecompute-export" + manifestpostprocessor "github.com/mitchellh/packer/post-processor/manifest" + shelllocalpostprocessor "github.com/mitchellh/packer/post-processor/shell-local" + vagrantpostprocessor "github.com/mitchellh/packer/post-processor/vagrant" + vagrantcloudpostprocessor "github.com/mitchellh/packer/post-processor/vagrant-cloud" vspherepostprocessor "github.com/mitchellh/packer/post-processor/vsphere" + ansibleprovisioner "github.com/mitchellh/packer/provisioner/ansible" + ansiblelocalprovisioner "github.com/mitchellh/packer/provisioner/ansible-local" + chefclientprovisioner "github.com/mitchellh/packer/provisioner/chef-client" + chefsoloprovisioner "github.com/mitchellh/packer/provisioner/chef-solo" + fileprovisioner "github.com/mitchellh/packer/provisioner/file" + powershellprovisioner "github.com/mitchellh/packer/provisioner/powershell" + puppetmasterlessprovisioner "github.com/mitchellh/packer/provisioner/puppet-masterless" + puppetserverprovisioner "github.com/mitchellh/packer/provisioner/puppet-server" + saltmasterlessprovisioner "github.com/mitchellh/packer/provisioner/salt-masterless" + shellprovisioner "github.com/mitchellh/packer/provisioner/shell" + shelllocalprovisioner "github.com/mitchellh/packer/provisioner/shell-local" windowsrestartprovisioner "github.com/mitchellh/packer/provisioner/windows-restart" windowsshellprovisioner "github.com/mitchellh/packer/provisioner/windows-shell" - ) type PluginCommand struct { @@ -67,61 +66,58 @@ type PluginCommand struct { var Builders = map[string]packer.Builder{ "amazon-chroot": new(amazonchrootbuilder.Builder), - "amazon-ebs": new(amazonebsbuilder.Builder), - "amazon-instance": new(amazoninstancebuilder.Builder), - "azure-arm": new(azurearmbuilder.Builder), - "digitalocean": new(digitaloceanbuilder.Builder), - "docker": new(dockerbuilder.Builder), - "file": new(filebuilder.Builder), + "amazon-ebs": new(amazonebsbuilder.Builder), + "amazon-instance": new(amazoninstancebuilder.Builder), + "azure-arm": new(azurearmbuilder.Builder), + "digitalocean": new(digitaloceanbuilder.Builder), + "docker": new(dockerbuilder.Builder), + "file": new(filebuilder.Builder), "googlecompute": new(googlecomputebuilder.Builder), - "null": new(nullbuilder.Builder), - "openstack": new(openstackbuilder.Builder), + "null": new(nullbuilder.Builder), + "openstack": new(openstackbuilder.Builder), "parallels-iso": new(parallelsisobuilder.Builder), "parallels-pvm": new(parallelspvmbuilder.Builder), - "qemu": new(qemubuilder.Builder), - "virtualbox-iso": new(virtualboxisobuilder.Builder), - "virtualbox-ovf": new(virtualboxovfbuilder.Builder), - "vmware-iso": new(vmwareisobuilder.Builder), - "vmware-vmx": new(vmwarevmxbuilder.Builder), + "qemu": new(qemubuilder.Builder), + "virtualbox-iso": new(virtualboxisobuilder.Builder), + "virtualbox-ovf": new(virtualboxovfbuilder.Builder), + "vmware-iso": new(vmwareisobuilder.Builder), + "vmware-vmx": new(vmwarevmxbuilder.Builder), } - var Provisioners = map[string]packer.Provisioner{ - "ansible": new(ansibleprovisioner.Provisioner), - "ansible-local": new(ansiblelocalprovisioner.Provisioner), - "chef-client": new(chefclientprovisioner.Provisioner), - "chef-solo": new(chefsoloprovisioner.Provisioner), - "file": new(fileprovisioner.Provisioner), - "powershell": new(powershellprovisioner.Provisioner), - "puppet-masterless": new(puppetmasterlessprovisioner.Provisioner), - "puppet-server": new(puppetserverprovisioner.Provisioner), + "ansible": new(ansibleprovisioner.Provisioner), + "ansible-local": new(ansiblelocalprovisioner.Provisioner), + "chef-client": new(chefclientprovisioner.Provisioner), + "chef-solo": new(chefsoloprovisioner.Provisioner), + "file": new(fileprovisioner.Provisioner), + "powershell": new(powershellprovisioner.Provisioner), + "puppet-masterless": new(puppetmasterlessprovisioner.Provisioner), + "puppet-server": new(puppetserverprovisioner.Provisioner), "salt-masterless": new(saltmasterlessprovisioner.Provisioner), - "shell": new(shellprovisioner.Provisioner), - "shell-local": new(shelllocalprovisioner.Provisioner), + "shell": new(shellprovisioner.Provisioner), + "shell-local": new(shelllocalprovisioner.Provisioner), "windows-restart": new(windowsrestartprovisioner.Provisioner), - "windows-shell": new(windowsshellprovisioner.Provisioner), + "windows-shell": new(windowsshellprovisioner.Provisioner), } - var PostProcessors = map[string]packer.PostProcessor{ - "amazon-import": new(amazonimportpostprocessor.PostProcessor), - "artifice": new(artificepostprocessor.PostProcessor), - "atlas": new(atlaspostprocessor.PostProcessor), - "checksum": new(checksumpostprocessor.PostProcessor), - "compress": new(compresspostprocessor.PostProcessor), - "docker-import": new(dockerimportpostprocessor.PostProcessor), - "docker-push": new(dockerpushpostprocessor.PostProcessor), - "docker-save": new(dockersavepostprocessor.PostProcessor), - "docker-tag": new(dockertagpostprocessor.PostProcessor), - "googlecompute-export": new(googlecomputeexportpostprocessor.PostProcessor), - "manifest": new(manifestpostprocessor.PostProcessor), - "shell-local": new(shelllocalpostprocessor.PostProcessor), - "vagrant": new(vagrantpostprocessor.PostProcessor), - "vagrant-cloud": new(vagrantcloudpostprocessor.PostProcessor), - "vsphere": new(vspherepostprocessor.PostProcessor), + "amazon-import": new(amazonimportpostprocessor.PostProcessor), + "artifice": new(artificepostprocessor.PostProcessor), + "atlas": new(atlaspostprocessor.PostProcessor), + "checksum": new(checksumpostprocessor.PostProcessor), + "compress": new(compresspostprocessor.PostProcessor), + "docker-import": new(dockerimportpostprocessor.PostProcessor), + "docker-push": new(dockerpushpostprocessor.PostProcessor), + "docker-save": new(dockersavepostprocessor.PostProcessor), + "docker-tag": new(dockertagpostprocessor.PostProcessor), + "googlecompute-export": new(googlecomputeexportpostprocessor.PostProcessor), + "manifest": new(manifestpostprocessor.PostProcessor), + "shell-local": new(shelllocalpostprocessor.PostProcessor), + "vagrant": new(vagrantpostprocessor.PostProcessor), + "vagrant-cloud": new(vagrantcloudpostprocessor.PostProcessor), + "vsphere": new(vspherepostprocessor.PostProcessor), } - var pluginRegexp = regexp.MustCompile("packer-(builder|post-processor|provisioner)-(.+)") func (c *PluginCommand) Run(args []string) int { diff --git a/communicator/none/communicator_test.go b/communicator/none/communicator_test.go index fd5c6b13c..1153afb5c 100644 --- a/communicator/none/communicator_test.go +++ b/communicator/none/communicator_test.go @@ -13,4 +13,3 @@ func TestCommIsCommunicator(t *testing.T) { t.Fatalf("comm must be a communicator") } } - diff --git a/post-processor/googlecompute-export/post-processor.go b/post-processor/googlecompute-export/post-processor.go index e835f30a9..c45a6f67d 100644 --- a/post-processor/googlecompute-export/post-processor.go +++ b/post-processor/googlecompute-export/post-processor.go @@ -81,7 +81,7 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac RawStateTimeout: "5m", } exporterConfig.CalcTimeout() - + // Set up credentials and GCE driver. b, err := ioutil.ReadFile(accountKeyFilePath) if err != nil { diff --git a/post-processor/manifest/post-processor.go b/post-processor/manifest/post-processor.go index 0b543d3a4..7b4507cf6 100644 --- a/post-processor/manifest/post-processor.go +++ b/post-processor/manifest/post-processor.go @@ -18,9 +18,9 @@ import ( type Config struct { common.PackerConfig `mapstructure:",squash"` - Filename string `mapstructure:"filename"` - StripPath bool `mapstructure:"strip_path"` - ctx interpolate.Context + Filename string `mapstructure:"filename"` + StripPath bool `mapstructure:"strip_path"` + ctx interpolate.Context } type PostProcessor struct { diff --git a/provisioner/chef-client/provisioner.go b/provisioner/chef-client/provisioner.go index b85388b6b..33304d983 100644 --- a/provisioner/chef-client/provisioner.go +++ b/provisioner/chef-client/provisioner.go @@ -98,9 +98,9 @@ type InstallChefTemplate struct { } type KnifeTemplate struct { - Sudo bool - Flags string - Args string + Sudo bool + Flags string + Args string } func (p *Provisioner) Prepare(raws ...interface{}) error { @@ -500,7 +500,7 @@ func (p *Provisioner) knifeExec(ui packer.Ui, comm packer.Communicator, node str } p.config.ctx.Data = &KnifeTemplate{ - Sudo: !p.config.PreventSudo, + Sudo: !p.config.PreventSudo, Flags: strings.Join(flags, " "), Args: strings.Join(args, " "), } diff --git a/provisioner/puppet-server/provisioner.go b/provisioner/puppet-server/provisioner.go index d0f49aa19..a15936a1c 100644 --- a/provisioner/puppet-server/provisioner.go +++ b/provisioner/puppet-server/provisioner.go @@ -16,7 +16,7 @@ import ( type Config struct { common.PackerConfig `mapstructure:",squash"` ctx interpolate.Context - + // The command used to execute Puppet. ExecuteCommand string `mapstructure:"execute_command"` @@ -76,11 +76,11 @@ func (p *Provisioner) Prepare(raws ...interface{}) error { if err != nil { return err } - + if p.config.ExecuteCommand == "" { p.config.ExecuteCommand = p.commandTemplate() } - + if p.config.StagingDir == "" { p.config.StagingDir = "/tmp/packer-puppet-server" } diff --git a/provisioner/shell/provisioner_test.go b/provisioner/shell/provisioner_test.go index 6f6b5424a..0b87da7bf 100644 --- a/provisioner/shell/provisioner_test.go +++ b/provisioner/shell/provisioner_test.go @@ -4,9 +4,9 @@ import ( "github.com/mitchellh/packer/packer" "io/ioutil" "os" - "testing" - "strings" "regexp" + "strings" + "testing" ) func testConfig() map[string]interface{} { @@ -306,7 +306,7 @@ func TestProvisioner_RemotePathSetViaRemotePathAndRemoteFile(t *testing.T) { t.Fatalf("should not have error: %s", err) } - if p.config.RemotePath != expectedRemoteFolder + "/" + expectedRemoteFile { + if p.config.RemotePath != expectedRemoteFolder+"/"+expectedRemoteFile { t.Fatalf("remote path does not contain remote_file") } }