forked from cloudfoundry/bosh-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fake_manager.go
91 lines (75 loc) · 2.1 KB
/
fake_manager.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
package fakes
import (
"fmt"
bistemcell "github.com/cloudfoundry/bosh-cli/stemcell"
biui "github.com/cloudfoundry/bosh-cli/ui"
bosherr "github.com/cloudfoundry/bosh-utils/errors"
)
type FakeManager struct {
UploadInputs []UploadInput
uploadBehavior map[UploadInput]uploadOutput
findUnusedOutput findUnusedOutput
DeleteUnusedCalledTimes int
DeleteUnusedErr error
}
type UploadInput struct {
Stemcell bistemcell.ExtractedStemcell
Stage biui.Stage
}
type uploadOutput struct {
stemcell bistemcell.CloudStemcell
err error
}
type findUnusedOutput struct {
stemcells []bistemcell.CloudStemcell
err error
}
func NewFakeManager() *FakeManager {
return &FakeManager{
UploadInputs: []UploadInput{},
uploadBehavior: map[UploadInput]uploadOutput{},
}
}
func (m *FakeManager) FindCurrent() ([]bistemcell.CloudStemcell, error) {
return []bistemcell.CloudStemcell{}, bosherr.Error("FakeManager.FindCurrent() not implemented (yet)")
}
func (m *FakeManager) Upload(stemcell bistemcell.ExtractedStemcell, stage biui.Stage) (bistemcell.CloudStemcell, error) {
input := UploadInput{
Stemcell: stemcell,
Stage: stage,
}
m.UploadInputs = append(m.UploadInputs, input)
output, found := m.uploadBehavior[input]
if !found {
return nil, fmt.Errorf("Unsupported Upload Input: %#v", stemcell)
}
return output.stemcell, output.err
}
func (m *FakeManager) FindUnused() ([]bistemcell.CloudStemcell, error) {
return m.findUnusedOutput.stemcells, m.findUnusedOutput.err
}
func (m *FakeManager) DeleteUnused(eventLoggerStage biui.Stage) error {
m.DeleteUnusedCalledTimes++
return m.DeleteUnusedErr
}
func (m *FakeManager) SetUploadBehavior(
extractedStemcell bistemcell.ExtractedStemcell,
stage biui.Stage,
cloudStemcell bistemcell.CloudStemcell,
err error,
) {
input := UploadInput{
Stemcell: extractedStemcell,
Stage: stage,
}
m.uploadBehavior[input] = uploadOutput{stemcell: cloudStemcell, err: err}
}
func (m *FakeManager) SetFindUnusedBehavior(
stemcells []bistemcell.CloudStemcell,
err error,
) {
m.findUnusedOutput = findUnusedOutput{
stemcells: stemcells,
err: err,
}
}