builder/amazon/chroot: switch func type to interface

Was getting weird behavior... see
https://groups.google.com/d/msg/golang-nuts/a1kymwSVt2M/FwcCuBl1_48
This commit is contained in:
Mitchell Hashimoto 2013-07-30 17:56:42 -07:00
parent 668631bd87
commit 3667340768
11 changed files with 56 additions and 10 deletions

View File

@ -18,10 +18,6 @@ import (
// The unique ID for this builder
const BuilderId = "mitchellh.amazon.chroot"
// CleanupFunc is a type that is strung throughout the state bag in
// order to perform cleanup at earlier points.
type CleanupFunc func(map[string]interface{}) error
// Config is the configuration that is chained through the steps and
// settable from the template.
type Config struct {

View File

@ -0,0 +1,6 @@
package chroot
// Cleanup is an interface that some steps implement for early cleanup.
type Cleanup interface {
CleanupFunc(map[string]interface{}) error
}

View File

@ -71,7 +71,7 @@ func (s *StepAttachVolume) Run(state map[string]interface{}) multistep.StepActio
}
state["device"] = config.AttachedDevicePath
state["attach_cleanup"] = s.CleanupFunc
state["attach_cleanup"] = s
return multistep.ActionContinue
}

View File

@ -0,0 +1,11 @@
package chroot
import "testing"
func TestAttachVolumeCleanupFunc_ImplementsCleanupFunc(t *testing.T) {
var raw interface{}
raw = new(StepAttachVolume)
if _, ok := raw.(Cleanup); !ok {
t.Fatalf("cleanup func should be a CleanupFunc")
}
}

View File

@ -43,7 +43,7 @@ func (s *StepCopyFiles) Run(state map[string]interface{}) multistep.StepAction {
}
}
state["copy_files_cleanup"] = s.CleanupFunc
state["copy_files_cleanup"] = s
return multistep.ActionContinue
}

View File

@ -0,0 +1,11 @@
package chroot
import "testing"
func TestCopyFilesCleanupFunc_ImplementsCleanupFunc(t *testing.T) {
var raw interface{}
raw = new(StepCopyFiles)
if _, ok := raw.(Cleanup); !ok {
t.Fatalf("cleanup func should be a CleanupFunc")
}
}

View File

@ -21,9 +21,9 @@ func (s *StepEarlyCleanup) Run(state map[string]interface{}) multistep.StepActio
}
for _, key := range cleanupKeys {
f := state[key].(CleanupFunc)
c := state[key].(Cleanup)
log.Printf("Running cleanup func: %s", key)
if err := f(state); err != nil {
if err := c.CleanupFunc(state); err != nil {
err := fmt.Errorf("Error cleaning up: %s", err)
state["error"] = err
ui.Error(err.Error())

View File

@ -62,7 +62,7 @@ func (s *StepMountDevice) Run(state map[string]interface{}) multistep.StepAction
// Set the mount path so we remember to unmount it later
s.mountPath = mountPath
state["mount_path"] = s.mountPath
state["mount_device_cleanup"] = s.CleanupFunc
state["mount_device_cleanup"] = s
return multistep.ActionContinue
}

View File

@ -0,0 +1,11 @@
package chroot
import "testing"
func TestMountDeviceCleanupFunc_ImplementsCleanupFunc(t *testing.T) {
var raw interface{}
raw = new(StepMountDevice)
if _, ok := raw.(Cleanup); !ok {
t.Fatalf("cleanup func should be a CleanupFunc")
}
}

View File

@ -61,7 +61,7 @@ func (s *StepMountExtra) Run(state map[string]interface{}) multistep.StepAction
s.mounts = append(s.mounts, innerPath)
}
state["mount_extra_cleanup"] = s.CleanupFunc
state["mount_extra_cleanup"] = s
return multistep.ActionContinue
}

View File

@ -0,0 +1,11 @@
package chroot
import "testing"
func TestMountExtraCleanupFunc_ImplementsCleanupFunc(t *testing.T) {
var raw interface{}
raw = new(StepMountExtra)
if _, ok := raw.(Cleanup); !ok {
t.Fatalf("cleanup func should be a CleanupFunc")
}
}