1package fakes
2
3import (
4	bicloud "github.com/cloudfoundry/bosh-cli/cloud"
5)
6
7type FakeCPICmdRunner struct {
8	CurrentRunInput     []RunInput
9	CurrentRunCmdOutput bicloud.CmdOutput
10	CurrentRunError     error
11	RunInputs           [][]RunInput
12	RunCmdOutputs       []bicloud.CmdOutput
13	RunErrs             []error
14}
15
16type RunInput struct {
17	Context    bicloud.CmdContext
18	Method     string
19	Arguments  []interface{}
20	ApiVersion int
21}
22
23func NewFakeCPICmdRunner() *FakeCPICmdRunner {
24	return &FakeCPICmdRunner{}
25}
26
27func (r *FakeCPICmdRunner) Run(context bicloud.CmdContext, method string, apiVersion int, args ...interface{}) (bicloud.CmdOutput, error) {
28	if len(r.RunCmdOutputs) > 0 {
29		r.CurrentRunCmdOutput = r.RunCmdOutputs[0]
30
31		if len(r.RunCmdOutputs) > 1 {
32			r.RunCmdOutputs = r.RunCmdOutputs[1:]
33		}
34	}
35
36	if len(r.RunInputs) > 0 {
37		r.CurrentRunInput = r.RunInputs[0]
38
39		if len(r.RunInputs) > 1 {
40			r.RunInputs = r.RunInputs[1:]
41		}
42	}
43
44	if len(r.RunErrs) > 0 {
45		r.CurrentRunError = r.RunErrs[0]
46
47		if len(r.RunErrs) > 1 {
48			r.RunErrs = r.RunErrs[1:]
49		}
50	}
51
52	r.CurrentRunInput = append(r.CurrentRunInput, RunInput{
53		Context:    context,
54		Method:     method,
55		Arguments:  args,
56		ApiVersion: apiVersion,
57	})
58
59	return r.CurrentRunCmdOutput, r.CurrentRunError
60}
61