forked from cloudfoundry-attic/bosh-init
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fake_extractor.go
95 lines (77 loc) · 2.68 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package fakes
import (
"fmt"
boshcmd "github.com/cloudfoundry/bosh-agent/platform/commands"
)
type decompressInput struct {
srcFile string
destDir string
}
type decompressOutput struct {
err error
}
type compressInput struct {
srcDir string
}
type compressOutput struct {
destFile string
err error
}
type cleanUpInput struct {
tarballPath string
}
type cleanUpOutput struct {
err error
}
type decompressError error
type FakeMultiResponseExtractor struct {
decompressBehavior map[decompressInput]decompressError
compressBehavior map[compressInput]compressOutput
cleanUpBehavior map[cleanUpInput]cleanUpOutput
decompressedInputs []decompressInput
}
func NewFakeMultiResponseExtractor() *FakeMultiResponseExtractor {
return &FakeMultiResponseExtractor{decompressBehavior: map[decompressInput]decompressError{}}
}
func (e *FakeMultiResponseExtractor) DecompressFileToDir(srcFile, destDir string, options boshcmd.CompressorOptions) error {
decompressInput := decompressInput{srcFile: srcFile, destDir: destDir}
decompressError := e.decompressBehavior[decompressInput]
if decompressError != nil {
return decompressError
}
e.decompressedInputs = append(e.decompressedInputs, decompressInput)
return nil
}
func (e *FakeMultiResponseExtractor) SetDecompressBehavior(srcFile, destDir string, err decompressError) {
e.decompressBehavior[decompressInput{srcFile: srcFile, destDir: destDir}] = err
}
func (e *FakeMultiResponseExtractor) DecompressedFiles() []string {
files := make([]string, 0, len(e.decompressedInputs))
for _, decompressedInput := range e.decompressedInputs {
file := fmt.Sprintf("%s/%s", decompressedInput.destDir, decompressedInput.srcFile)
files = append(files, file)
}
return files
}
func (e *FakeMultiResponseExtractor) CompressFilesInDir(srcDir string) (string, error) {
input := compressInput{srcDir: srcDir}
output, found := e.compressBehavior[input]
if found {
return output.destFile, output.err
}
return "", fmt.Errorf("Unsupported Input: CompressFilesInDir('%s')\nAvailable inputs: %#v", srcDir, e.compressBehavior)
}
func (e *FakeMultiResponseExtractor) SetCompressBehavior(srcDir, destFile string, err error) {
e.compressBehavior[compressInput{srcDir: srcDir}] = compressOutput{destFile: destFile, err: err}
}
func (e *FakeMultiResponseExtractor) CleanUp(tarballPath string) error {
input := cleanUpInput{tarballPath: tarballPath}
output, found := e.cleanUpBehavior[input]
if found {
return output.err
}
return fmt.Errorf("Unsupported Input: CleanUp('%s')", tarballPath)
}
func (e *FakeMultiResponseExtractor) SetCleanUpBehavior(tarballPath string, err error) {
e.cleanUpBehavior[cleanUpInput{tarballPath: tarballPath}] = cleanUpOutput{err: err}
}