-
Notifications
You must be signed in to change notification settings - Fork 115
/
fake_bundle_collection.go
61 lines (47 loc) · 1.23 KB
/
fake_bundle_collection.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
package fakes
import (
"errors"
bc "github.com/cloudfoundry/bosh-agent/agent/applier/bundlecollection"
)
type FakeBundleCollection struct {
bundles map[BundleKey]*FakeBundle
ListBundles []bc.Bundle
ListErr error
GetErr error
}
type BundleKey struct {
Name string
Version string
}
func NewBundleKey(definition bc.BundleDefinition) BundleKey {
return BundleKey{
Name: definition.BundleName(),
Version: definition.BundleVersion(),
}
}
func NewFakeBundleCollection() *FakeBundleCollection {
return &FakeBundleCollection{
bundles: map[BundleKey]*FakeBundle{},
}
}
func (s *FakeBundleCollection) Get(definition bc.BundleDefinition) (bc.Bundle, error) {
if len(definition.BundleName()) == 0 {
return nil, errors.New("missing bundle name")
}
if len(definition.BundleVersion()) == 0 {
return nil, errors.New("missing bundle version")
}
return s.FakeGet(definition), s.GetErr
}
func (s *FakeBundleCollection) FakeGet(definition bc.BundleDefinition) *FakeBundle {
key := NewBundleKey(definition)
bundle, found := s.bundles[key]
if !found {
bundle = NewFakeBundle()
s.bundles[key] = bundle
}
return bundle
}
func (s *FakeBundleCollection) List() ([]bc.Bundle, error) {
return s.ListBundles, s.ListErr
}