fixing up types.
This commit is contained in:
parent
299ee6efd2
commit
40e15c84ef
|
@ -82,3 +82,14 @@ func TestBuilderPrepare_SourceAmi(t *testing.T) {
|
||||||
t.Errorf("err: %s", err)
|
t.Errorf("err: %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestBuilderPrepare_CommandWrapper(t *testing.T) {
|
||||||
|
b := &Builder{}
|
||||||
|
config := testConfig()
|
||||||
|
|
||||||
|
config["command_wrapper"] = "echo hi; {{.Command}}"
|
||||||
|
err := b.Prepare(config)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("err: %s", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -18,8 +18,10 @@ func TestCopyFile(t *testing.T) {
|
||||||
if _, err = first.WriteString(payload); err != nil {
|
if _, err = first.WriteString(payload); err != nil {
|
||||||
t.Fatalf("Couldn't write payload to first file.")
|
t.Fatalf("Couldn't write payload to first file.")
|
||||||
}
|
}
|
||||||
|
first.Sync()
|
||||||
|
|
||||||
if err := copySingle(newName, first.Name(), "cp"); err != nil {
|
cmd := ShellCommand(fmt.Sprintf("cp %s %s", first.Name(), newName))
|
||||||
|
if err := cmd.Run(); err != nil {
|
||||||
t.Fatalf("Couldn't copy file")
|
t.Fatalf("Couldn't copy file")
|
||||||
}
|
}
|
||||||
defer os.Remove(newName)
|
defer os.Remove(newName)
|
||||||
|
|
|
@ -13,7 +13,7 @@ type StepChrootProvision struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type WrappedCommandTemplate struct {
|
type WrappedCommandTemplate struct {
|
||||||
command string
|
Command string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StepChrootProvision) Run(state multistep.StateBag) multistep.StepAction {
|
func (s *StepChrootProvision) Run(state multistep.StateBag) multistep.StepAction {
|
||||||
|
@ -26,7 +26,7 @@ func (s *StepChrootProvision) Run(state multistep.StateBag) multistep.StepAction
|
||||||
}
|
}
|
||||||
wrappedCommand := func(command string) *exec.Cmd {
|
wrappedCommand := func(command string) *exec.Cmd {
|
||||||
wrapped, err := config.tpl.Process(config.CommandWrapper, &WrappedCommandTemplate{
|
wrapped, err := config.tpl.Process(config.CommandWrapper, &WrappedCommandTemplate{
|
||||||
command: command,
|
Command: command,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ui.Error(err.Error())
|
ui.Error(err.Error())
|
||||||
|
|
|
@ -60,7 +60,6 @@ func (s *StepCopyFiles) CleanupFunc(state multistep.StateBag) error {
|
||||||
for _, file := range s.files {
|
for _, file := range s.files {
|
||||||
log.Printf("Removing: %s", file)
|
log.Printf("Removing: %s", file)
|
||||||
localCmd := wrappedCommand(fmt.Sprintf("rm -f %s", file))
|
localCmd := wrappedCommand(fmt.Sprintf("rm -f %s", file))
|
||||||
log.Println(localCmd.Args)
|
|
||||||
if err := localCmd.Run(); err != nil {
|
if err := localCmd.Run(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,7 +59,7 @@ func (s *StepMountDevice) Run(state multistep.StateBag) multistep.StepAction {
|
||||||
ui.Say("Mounting the root device...")
|
ui.Say("Mounting the root device...")
|
||||||
stderr := new(bytes.Buffer)
|
stderr := new(bytes.Buffer)
|
||||||
mountCommand := fmt.Sprintf("mount %s %s", device, mountPath)
|
mountCommand := fmt.Sprintf("mount %s %s", device, mountPath)
|
||||||
wrappedCommand := state.Get("wrappedCommand").(Command)
|
wrappedCommand := state.Get("wrappedCommand").(*Command)
|
||||||
cmd := wrappedCommand(mountCommand)
|
cmd := wrappedCommand(mountCommand)
|
||||||
cmd.Stderr = stderr
|
cmd.Stderr = stderr
|
||||||
if err := cmd.Run(); err != nil {
|
if err := cmd.Run(); err != nil {
|
||||||
|
|
Loading…
Reference in New Issue