File: reporter.go

package info (click to toggle)
golang-github-approvals-go-approval-tests 0.0~git20180620.6ae1ec6-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 296 kB
  • sloc: xml: 16; makefile: 3
file content (53 lines) | stat: -rw-r--r-- 1,326 bytes parent folder | download | duplicates (3)
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
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,
	}
}