remove convoluted pointer logic

This commit is contained in:
Matthew Hooker 2017-10-11 23:35:24 -07:00
parent e497c6027f
commit 75111e49e9
No known key found for this signature in database
GPG Key ID: 7B5F933D9CE8C6A1
2 changed files with 7 additions and 12 deletions

View File

@ -71,7 +71,7 @@ type Config struct {
// Whether to clean scripts up // Whether to clean scripts up
SkipClean bool `mapstructure:"skip_clean"` SkipClean bool `mapstructure:"skip_clean"`
ExpectDisconnect *bool `mapstructure:"expect_disconnect"` ExpectDisconnect bool `mapstructure:"expect_disconnect"`
startRetryTimeout time.Duration startRetryTimeout time.Duration
ctx interpolate.Context ctx interpolate.Context
@ -104,11 +104,6 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
p.config.ExecuteCommand = "chmod +x {{.Path}}; {{.Vars}} {{.Path}}" 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 { if p.config.Inline != nil && len(p.config.Inline) == 0 {
p.config.Inline = nil 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 // If the exit code indicates a remote disconnect, fail unless
// we were expecting it. // we were expecting it.
if cmd.ExitStatus == packer.CmdDisconnect { if cmd.ExitStatus == packer.CmdDisconnect {
if !*p.config.ExpectDisconnect { if !p.config.ExpectDisconnect {
return fmt.Errorf("Script disconnected unexpectedly.") return fmt.Errorf("Script disconnected unexpectedly.")
} }
} else if cmd.ExitStatus != 0 { } else if cmd.ExitStatus != 0 {

View File

@ -1,12 +1,13 @@
package shell package shell
import ( import (
"github.com/hashicorp/packer/packer"
"io/ioutil" "io/ioutil"
"os" "os"
"regexp" "regexp"
"strings" "strings"
"testing" "testing"
"github.com/hashicorp/packer/packer"
) )
func testConfig() map[string]interface{} { func testConfig() map[string]interface{} {
@ -32,7 +33,7 @@ func TestProvisionerPrepare_Defaults(t *testing.T) {
t.Fatalf("err: %s", err) t.Fatalf("err: %s", err)
} }
if *p.config.ExpectDisconnect != false { if p.config.ExpectDisconnect != false {
t.Errorf("expected ExpectDisconnect to default to false") t.Errorf("expected ExpectDisconnect to default to false")
} }
@ -51,7 +52,7 @@ func TestProvisionerPrepare_ExpectDisconnect(t *testing.T) {
t.Fatalf("err: %s", err) t.Fatalf("err: %s", err)
} }
if *p.config.ExpectDisconnect != false { if p.config.ExpectDisconnect != false {
t.Errorf("expected ExpectDisconnect to be false") t.Errorf("expected ExpectDisconnect to be false")
} }
@ -62,10 +63,9 @@ func TestProvisionerPrepare_ExpectDisconnect(t *testing.T) {
t.Fatalf("err: %s", err) t.Fatalf("err: %s", err)
} }
if *p.config.ExpectDisconnect != true { if p.config.ExpectDisconnect != true {
t.Errorf("expected ExpectDisconnect to be true") t.Errorf("expected ExpectDisconnect to be true")
} }
} }
func TestProvisionerPrepare_InlineShebang(t *testing.T) { func TestProvisionerPrepare_InlineShebang(t *testing.T) {