forked from cloudfoundry/bosh-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fake_validator.go
79 lines (65 loc) · 2.51 KB
/
fake_validator.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
package manifestfakes
import (
bosherr "github.com/cloudfoundry/bosh-utils/errors"
bideplmanifest "github.com/cloudfoundry/bosh-cli/deployment/manifest"
biinstall "github.com/cloudfoundry/bosh-cli/installation"
birelsetmanifest "github.com/cloudfoundry/bosh-cli/release/set/manifest"
)
type FakeValidator struct {
ValidateInputs []ValidateInput
ValidateReleaseJobsInputs []ValidateReleaseJobsInput
validateOutputs []ValidateOutput
validateReleaseJobsOutputs []ValidateReleaseJobsOutput
}
func NewFakeValidator() *FakeValidator {
return &FakeValidator{
ValidateInputs: []ValidateInput{},
ValidateReleaseJobsInputs: []ValidateReleaseJobsInput{},
validateOutputs: []ValidateOutput{},
validateReleaseJobsOutputs: []ValidateReleaseJobsOutput{},
}
}
type ValidateInput struct {
Manifest bideplmanifest.Manifest
ReleaseSetManifest birelsetmanifest.Manifest
}
type ValidateReleaseJobsInput struct {
Manifest bideplmanifest.Manifest
ReleaseManager biinstall.ReleaseManager
}
type ValidateOutput struct {
Err error
}
type ValidateReleaseJobsOutput struct {
Err error
}
func (v *FakeValidator) Validate(manifest bideplmanifest.Manifest, releaseSetManifest birelsetmanifest.Manifest) error {
v.ValidateInputs = append(v.ValidateInputs, ValidateInput{
Manifest: manifest,
ReleaseSetManifest: releaseSetManifest,
})
if len(v.validateOutputs) == 0 {
return bosherr.Errorf("Unexpected FakeValidator.Validate(manifest, releaseSetManifest) called with manifest: %#v", manifest)
}
validateOutput := v.validateOutputs[0]
v.validateOutputs = v.validateOutputs[1:]
return validateOutput.Err
}
func (v *FakeValidator) ValidateReleaseJobs(manifest bideplmanifest.Manifest, releaseManager biinstall.ReleaseManager) error {
v.ValidateReleaseJobsInputs = append(v.ValidateReleaseJobsInputs, ValidateReleaseJobsInput{
Manifest: manifest,
ReleaseManager: releaseManager,
})
if len(v.validateReleaseJobsOutputs) == 0 {
return bosherr.Errorf("Unexpected FakeValidator.ValidateReleaseJobs(manifest, releaseManager) called with manifest: %#v", manifest)
}
validateReleaseJobsOutput := v.validateReleaseJobsOutputs[0]
v.validateReleaseJobsOutputs = v.validateReleaseJobsOutputs[1:]
return validateReleaseJobsOutput.Err
}
func (v *FakeValidator) SetValidateBehavior(outputs []ValidateOutput) {
v.validateOutputs = outputs
}
func (v *FakeValidator) SetValidateReleaseJobsBehavior(outputs []ValidateReleaseJobsOutput) {
v.validateReleaseJobsOutputs = outputs
}