forked from cloudfoundry-attic/bosh-init
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fake_manager_factory.go
63 lines (49 loc) · 1.57 KB
/
fake_manager_factory.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
package fakes
import (
"fmt"
bosherr "github.com/cloudfoundry/bosh-agent/errors"
bicloud "github.com/cloudfoundry/bosh-init/cloud"
bistemcell "github.com/cloudfoundry/bosh-init/stemcell"
bitestutils "github.com/cloudfoundry/bosh-init/testutils"
)
type NewManagerInput struct {
Cloud bicloud.Cloud
}
type newManagerOutput struct {
manager bistemcell.Manager
}
type FakeManagerFactory struct {
NewManagerInputs []NewManagerInput
newManagerBehavior map[string]newManagerOutput
}
func NewFakeManagerFactory() *FakeManagerFactory {
return &FakeManagerFactory{
NewManagerInputs: []NewManagerInput{},
newManagerBehavior: map[string]newManagerOutput{},
}
}
func (f *FakeManagerFactory) NewManager(cloud bicloud.Cloud) bistemcell.Manager {
input := NewManagerInput{
Cloud: cloud,
}
f.NewManagerInputs = append(f.NewManagerInputs, input)
inputString, marshalErr := bitestutils.MarshalToString(input)
if marshalErr != nil {
panic(bosherr.WrapError(marshalErr, "Marshaling NewManager input"))
}
output, found := f.newManagerBehavior[inputString]
if !found {
panic(fmt.Errorf("Unsupported NewManager Input: %#v\nExpected Behavior: %#v", input, f.newManagerBehavior))
}
return output.manager
}
func (f *FakeManagerFactory) SetNewManagerBehavior(cloud bicloud.Cloud, manager bistemcell.Manager) {
input := NewManagerInput{
Cloud: cloud,
}
inputString, marshalErr := bitestutils.MarshalToString(input)
if marshalErr != nil {
panic(bosherr.WrapError(marshalErr, "Marshaling NewManager input"))
}
f.newManagerBehavior[inputString] = newManagerOutput{manager: manager}
}