forked from cloudfoundry/bosh-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fake_applier.go
51 lines (41 loc) · 1.13 KB
/
fake_applier.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
package fakes
import (
"sync"
models "github.com/cloudfoundry/bosh-agent/agent/applier/models"
)
type FakeApplier struct {
ActionsCalled []string
PreparedPackages []models.Package
PrepareError error
AppliedPackages []models.Package
ApplyError error
KeptOnlyPackages []models.Package
KeepOnlyErr error
applyMutex sync.Mutex
PrepareStub func(pkg models.Package) error
}
func NewFakeApplier() *FakeApplier {
return &FakeApplier{
AppliedPackages: []models.Package{},
}
}
func (s *FakeApplier) Prepare(pkg models.Package) error {
s.applyMutex.Lock()
s.ActionsCalled = append(s.ActionsCalled, "Prepare")
s.PreparedPackages = append(s.PreparedPackages, pkg)
s.applyMutex.Unlock()
if s.PrepareStub != nil {
return s.PrepareStub(pkg)
}
return s.PrepareError
}
func (s *FakeApplier) Apply(pkg models.Package) error {
s.ActionsCalled = append(s.ActionsCalled, "Apply")
s.AppliedPackages = append(s.AppliedPackages, pkg)
return s.ApplyError
}
func (s *FakeApplier) KeepOnly(pkgs []models.Package) error {
s.ActionsCalled = append(s.ActionsCalled, "KeepOnly")
s.KeptOnlyPackages = pkgs
return s.KeepOnlyErr
}