package fakes

import (
	"fmt"

	boshsys "github.com/cloudfoundry/bosh-utils/system"
)

type FakePSRunner struct {
	RunCommands      []boshsys.PSCommand
	RunCommandErr    error
	runCommandErrors map[string]error
}

func NewFakePSRunner() *FakePSRunner {
	return &FakePSRunner{
		RunCommands:      []boshsys.PSCommand{},
		runCommandErrors: map[string]error{},
	}
}

func (r *FakePSRunner) RunCommand(cmd boshsys.PSCommand) (string, string, error) {
	r.RunCommands = append(r.RunCommands, cmd)
	if err := r.runCommandErrors[cmd.Script]; err != nil {
		return "", "", err
	}
	return "", "", r.RunCommandErr
}

func (r *FakePSRunner) RegisterRunCommandError(script string, err error) {
	if _, ok := r.runCommandErrors[script]; ok {
		panic(fmt.Sprintf("RunCommand error is already set for command: %s", script))
	}
	r.runCommandErrors[script] = err
}

package fakes

import boshsys "github.com/cloudfoundry/bosh-utils/system"

type FakePSRunner struct {
	RunCommands   []boshsys.PSCommand
	RunCommandErr error
}

func NewFakePSRunner() *FakePSRunner {
	return &FakePSRunner{
		RunCommands: []boshsys.PSCommand{},
	}
}

func (r *FakePSRunner) RunCommand(cmd boshsys.PSCommand) (string, string, error) {
	r.RunCommands = append(r.RunCommands, cmd)
	return "", "", r.RunCommandErr
}

--- 
+++ 
@@ -1,19 +1,35 @@
 package fakes
 
-import boshsys "github.com/cloudfoundry/bosh-utils/system"
+import (
+	"fmt"
+
+	boshsys "github.com/cloudfoundry/bosh-utils/system"
+)
 
 type FakePSRunner struct {
-	RunCommands   []boshsys.PSCommand
-	RunCommandErr error
+	RunCommands      []boshsys.PSCommand
+	RunCommandErr    error
+	runCommandErrors map[string]error
 }
 
 func NewFakePSRunner() *FakePSRunner {
 	return &FakePSRunner{
-		RunCommands: []boshsys.PSCommand{},
+		RunCommands:      []boshsys.PSCommand{},
+		runCommandErrors: map[string]error{},
 	}
 }
 
 func (r *FakePSRunner) RunCommand(cmd boshsys.PSCommand) (string, string, error) {
 	r.RunCommands = append(r.RunCommands, cmd)
+	if err := r.runCommandErrors[cmd.Script]; err != nil {
+		return "", "", err
+	}
 	return "", "", r.RunCommandErr
 }
+
+func (r *FakePSRunner) RegisterRunCommandError(script string, err error) {
+	if _, ok := r.runCommandErrors[script]; ok {
+		panic(fmt.Sprintf("RunCommand error is already set for command: %s", script))
+	}
+	r.runCommandErrors[script] = err
+}
Add a way to trigger specific errors on the PSRunner

Signed-off-by: Ben Moss <80bec717c12290923c80384e0a5fc28cdf75a97e@pivotal.io>
