1package stemcellfakes
2
3import (
4	"fmt"
5
6	bistemcell "github.com/cloudfoundry/bosh-cli/stemcell"
7)
8
9type ReadInput struct {
10	StemcellTarballPath string
11	DestPath            string
12}
13
14type ReadOutput struct {
15	stemcell bistemcell.ExtractedStemcell
16	err      error
17}
18
19type FakeStemcellReader struct {
20	ReadBehavior map[ReadInput]ReadOutput
21	ReadInputs   []ReadInput
22}
23
24func NewFakeReader() *FakeStemcellReader {
25	return &FakeStemcellReader{
26		ReadBehavior: map[ReadInput]ReadOutput{},
27		ReadInputs:   []ReadInput{},
28	}
29}
30
31func (fr *FakeStemcellReader) Read(stemcellTarballPath, destPath string) (bistemcell.ExtractedStemcell, error) {
32	input := ReadInput{
33		StemcellTarballPath: stemcellTarballPath,
34		DestPath:            destPath,
35	}
36	fr.ReadInputs = append(fr.ReadInputs, input)
37	output, found := fr.ReadBehavior[input]
38	if !found {
39		return nil, fmt.Errorf("Unsupported Input: Read('%#v', '%#v')", stemcellTarballPath, destPath)
40	}
41
42	return output.stemcell, output.err
43}
44
45func (fr *FakeStemcellReader) SetReadBehavior(stemcellTarballPath, destPath string, stemcell bistemcell.ExtractedStemcell, err error) {
46	input := ReadInput{
47		StemcellTarballPath: stemcellTarballPath,
48		DestPath:            destPath,
49	}
50	fr.ReadBehavior[input] = ReadOutput{stemcell: stemcell, err: err}
51}
52