From 75111e49e9e1da37fdd1406062cdf3033dc700e8 Mon Sep 17 00:00:00 2001 From: Matthew Hooker Date: Wed, 11 Oct 2017 23:35:24 -0700 Subject: [PATCH] remove convoluted pointer logic --- provisioner/shell/provisioner.go | 9 ++------- provisioner/shell/provisioner_test.go | 10 +++++----- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/provisioner/shell/provisioner.go b/provisioner/shell/provisioner.go index de88e7632..5233e50e7 100644 --- a/provisioner/shell/provisioner.go +++ b/provisioner/shell/provisioner.go @@ -71,7 +71,7 @@ type Config struct { // Whether to clean scripts up SkipClean bool `mapstructure:"skip_clean"` - ExpectDisconnect *bool `mapstructure:"expect_disconnect"` + ExpectDisconnect bool `mapstructure:"expect_disconnect"` startRetryTimeout time.Duration ctx interpolate.Context @@ -104,11 +104,6 @@ func (p *Provisioner) Prepare(raws ...interface{}) error { p.config.ExecuteCommand = "chmod +x {{.Path}}; {{.Vars}} {{.Path}}" } - if p.config.ExpectDisconnect == nil { - t := false - p.config.ExpectDisconnect = &t - } - if p.config.Inline != nil && len(p.config.Inline) == 0 { p.config.Inline = nil } @@ -287,7 +282,7 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error { // If the exit code indicates a remote disconnect, fail unless // we were expecting it. if cmd.ExitStatus == packer.CmdDisconnect { - if !*p.config.ExpectDisconnect { + if !p.config.ExpectDisconnect { return fmt.Errorf("Script disconnected unexpectedly.") } } else if cmd.ExitStatus != 0 { diff --git a/provisioner/shell/provisioner_test.go b/provisioner/shell/provisioner_test.go index b74fdbb13..c190f8c52 100644 --- a/provisioner/shell/provisioner_test.go +++ b/provisioner/shell/provisioner_test.go @@ -1,12 +1,13 @@ package shell import ( - "github.com/hashicorp/packer/packer" "io/ioutil" "os" "regexp" "strings" "testing" + + "github.com/hashicorp/packer/packer" ) func testConfig() map[string]interface{} { @@ -32,7 +33,7 @@ func TestProvisionerPrepare_Defaults(t *testing.T) { t.Fatalf("err: %s", err) } - if *p.config.ExpectDisconnect != false { + if p.config.ExpectDisconnect != false { t.Errorf("expected ExpectDisconnect to default to false") } @@ -51,7 +52,7 @@ func TestProvisionerPrepare_ExpectDisconnect(t *testing.T) { t.Fatalf("err: %s", err) } - if *p.config.ExpectDisconnect != false { + if p.config.ExpectDisconnect != false { t.Errorf("expected ExpectDisconnect to be false") } @@ -62,10 +63,9 @@ func TestProvisionerPrepare_ExpectDisconnect(t *testing.T) { t.Fatalf("err: %s", err) } - if *p.config.ExpectDisconnect != true { + if p.config.ExpectDisconnect != true { t.Errorf("expected ExpectDisconnect to be true") } - } func TestProvisionerPrepare_InlineShebang(t *testing.T) {