-
Notifications
You must be signed in to change notification settings - Fork 69
/
mock_empty_discoverer.go
57 lines (46 loc) · 1.16 KB
/
mock_empty_discoverer.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
package discovery
import (
"fmt"
"github.com/newrelic/newrelic-cli/internal/install/types"
)
func NewEmptyManifestValidator() *ManifestValidator {
return &ManifestValidator{}
}
type MockManifestValidator struct {
validators []validator
}
func NewMockManifestValidator(mockValidator validator) *ManifestValidator {
mv := ManifestValidator{
validators: []validator{mockValidator},
}
return &mv
}
func (mv *MockManifestValidator) Validate(m *types.DiscoveryManifest) error {
var accumulator error
errors := mv.FindAllValidationErrors(m)
for _, single := range errors {
if accumulator == nil {
accumulator = single
} else {
accumulator = fmt.Errorf("%s, %s", accumulator, single.Error())
}
}
if accumulator != nil {
// Flag as unsupported OS
m.IsUnsupported = true
return &types.UnsupportedOperatingSystemError{
Err: fmt.Errorf(errorPrefixFormat, accumulator),
}
}
return nil
}
func (mv *MockManifestValidator) FindAllValidationErrors(m *types.DiscoveryManifest) []error {
errors := []error{}
for _, validator := range mv.validators {
err := validator.Validate(m)
if err != nil {
errors = append(errors, err)
}
}
return errors
}