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