forked from cloudfoundry-attic/bosh-init
/
fake_extractor.go
41 lines (34 loc) · 1.03 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
package fakes
import (
"fmt"
)
type ExtractInput struct {
BlobID string
BlobSHA1 string
TargetDir string
}
type extractOutput struct {
err error
}
type FakeExtractor struct {
ExtractInputs []ExtractInput
extractBehavior map[ExtractInput]extractOutput
}
func NewFakeExtractor() *FakeExtractor {
return &FakeExtractor{
ExtractInputs: []ExtractInput{},
extractBehavior: map[ExtractInput]extractOutput{},
}
}
func (f *FakeExtractor) Extract(blobID string, blobSHA1 string, targetDir string) error {
input := ExtractInput{BlobID: blobID, BlobSHA1: blobSHA1, TargetDir: targetDir}
f.ExtractInputs = append(f.ExtractInputs, input)
output, found := f.extractBehavior[input]
if found {
return output.err
}
return fmt.Errorf("Unsupported Input: Extract('%s', '%s', '%s')", blobID, blobSHA1, targetDir)
}
func (f *FakeExtractor) SetExtractBehavior(blobID string, blobSHA1 string, targetDir string, err error) {
f.extractBehavior[ExtractInput{BlobID: blobID, BlobSHA1: blobSHA1, TargetDir: targetDir}] = extractOutput{err: err}
}