forked from cloudfoundry/bosh-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fake_extractor.go
52 lines (43 loc) · 1.11 KB
/
fake_extractor.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
52
package fakes
import (
"fmt"
bistemcell "github.com/cloudfoundry/bosh-cli/stemcell"
)
type ExtractInput struct {
TarballPath string
}
type extractOutput struct {
stemcell bistemcell.ExtractedStemcell
err error
}
type FakeExtractor struct {
ExtractInputs []ExtractInput
extractBehavior map[ExtractInput]extractOutput
}
func NewFakeExtractor() *FakeExtractor {
return &FakeExtractor{
ExtractInputs: []ExtractInput{},
extractBehavior: map[ExtractInput]extractOutput{},
}
}
func (e *FakeExtractor) Extract(tarballPath string) (bistemcell.ExtractedStemcell, error) {
input := ExtractInput{
TarballPath: tarballPath,
}
e.ExtractInputs = append(e.ExtractInputs, input)
output, found := e.extractBehavior[input]
if !found {
return nil, fmt.Errorf("Unsupported Upload Input: %s", tarballPath)
}
return output.stemcell, output.err
}
func (e *FakeExtractor) SetExtractBehavior(
tarballPath string,
extractedStemcell bistemcell.ExtractedStemcell,
err error,
) {
input := ExtractInput{
TarballPath: tarballPath,
}
e.extractBehavior[input] = extractOutput{stemcell: extractedStemcell, err: err}
}