X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/ce84723a4704a766f7e0dc3c61896733bf94f838..67e695ce526e9991649bd4d619338c767bbc1e05:/lib/crunchrun/logscanner_test.go diff --git a/lib/crunchrun/logscanner_test.go b/lib/crunchrun/logscanner_test.go index 26b128193a..f6b4ba3adc 100644 --- a/lib/crunchrun/logscanner_test.go +++ b/lib/crunchrun/logscanner_test.go @@ -17,12 +17,40 @@ func (s *logScannerSuite) TestCallReportFuncOnce(c *check.C) { var reported []string ls := logScanner{ Patterns: []string{"foobar", "barbaz"}, - ReportFunc: func(pattern string) { - reported = append(reported, pattern) + ReportFunc: func(pattern, detail string) { + reported = append(reported, pattern, detail) }, } - ls.Write([]byte("foo\nbar\nbar")) - ls.Write([]byte("baz\nwaz\nqux")) + ls.Write([]byte("foo\nbar\n2021-01-01T00:00:00.000Z: bar")) + ls.Write([]byte("baz: it's a detail\nwaz\nqux")) ls.Write([]byte("\nfoobar\n")) - c.Check(reported, check.DeepEquals, []string{"barbaz"}) + c.Check(reported, check.DeepEquals, []string{"barbaz", "2021-01-01T00:00:00.000Z: barbaz: it's a detail"}) +} + +func (s *logScannerSuite) TestOneWritePerLine(c *check.C) { + var reported []string + ls := logScanner{ + Patterns: []string{"barbaz"}, + ReportFunc: func(pattern, detail string) { + reported = append(reported, pattern, detail) + }, + } + ls.Write([]byte("foo\n")) + ls.Write([]byte("2021-01-01T00:00:00.000Z: barbaz: it's a detail\n")) + ls.Write([]byte("waz\n")) + c.Check(reported, check.DeepEquals, []string{"barbaz", "2021-01-01T00:00:00.000Z: barbaz: it's a detail"}) +} + +func (s *logScannerSuite) TestNoDetail(c *check.C) { + var reported []string + ls := logScanner{ + Patterns: []string{"barbaz"}, + ReportFunc: func(pattern, detail string) { + reported = append(reported, pattern, detail) + }, + } + ls.Write([]byte("foo\n")) + ls.Write([]byte("barbaz\n")) + ls.Write([]byte("waz\n")) + c.Check(reported, check.DeepEquals, []string{"barbaz", "barbaz"}) }