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
}

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
}

Add a way to trigger specific errors on the PSRunner
Add a way to trigger specific errors on the PSRunner

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