Slide 18
Slide 18 text
How mocks go wrong
Example 1 test
func TestSurveyReport(t *testing.T) {
var called bool
reportOutput := func(w io.Writer, cs []github.Comment) error {
called = true
require.Equal(t, comments(comment(author("World"))), cs, "expected the comments from the filter")
require.NotNilf(t, w, "expected a non-nil writer to have been passed in")
return nil
}
report := reporting.NewCommentsReport(reporting.FilterOnlySurveyComments, reportOutput)
err := report.Create(
comments(comment(author("Hello")), comment(author("World"))),
bytes.NewBuffer(nil),
)
require.NoError(t, err)
require.True(t, called)
}