This repository has been archived by the owner on Jan 5, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
/
fake_validator.go
78 lines (65 loc) · 2.47 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
package fakes
import (
bideplmanifest "github.com/cloudfoundry/bosh-init/deployment/manifest"
birel "github.com/cloudfoundry/bosh-init/release"
birelsetmanifest "github.com/cloudfoundry/bosh-init/release/set/manifest"
bosherr "github.com/cloudfoundry/bosh-utils/errors"
)
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 birel.Manager
}
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 birel.Manager) 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
}