packer-cn/vendor/github.com/approvals/go-approval-tests/reporters/reporter.go

54 lines
1.3 KiB
Go
Raw Normal View History

2016-07-11 18:08:28 -04:00
package reporters
// Reporter are called on failing approvals.
type Reporter interface {
// Report is called when the approved and received file do not match.
Report(approved, received string) bool
}
// FirstWorkingReporter reports using the first possible reporter.
type FirstWorkingReporter struct {
Reporters []Reporter
}
// Report is called when the approved and received file do not match.
func (s *FirstWorkingReporter) Report(approved, received string) bool {
for _, reporter := range s.Reporters {
result := reporter.Report(approved, received)
if result {
return true
}
}
return false
}
// NewFirstWorkingReporter creates in the order reporters are passed in.
func NewFirstWorkingReporter(reporters ...Reporter) Reporter {
return &FirstWorkingReporter{
Reporters: reporters,
}
}
// MultiReporter reports all reporters.
type MultiReporter struct {
Reporters []Reporter
}
// Report is called when the approved and received file do not match.
func (s *MultiReporter) Report(approved, received string) bool {
result := false
for _, reporter := range s.Reporters {
result = reporter.Report(approved, received) || result
}
return result
}
// NewMultiReporter calls all reporters.
func NewMultiReporter(reporters ...Reporter) Reporter {
return &MultiReporter{
Reporters: reporters,
}
}