1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
8 check "gopkg.in/check.v1"
11 var _ = check.Suite(&logScannerSuite{})
13 type logScannerSuite struct {
16 func (s *logScannerSuite) TestCallReportFuncOnce(c *check.C) {
19 Patterns: []string{"foobar", "barbaz"},
20 ReportFunc: func(pattern, detail string) {
21 reported = append(reported, pattern, detail)
24 ls.Write([]byte("foo\nbar\n2021-01-01T00:00:00.000Z: bar"))
25 ls.Write([]byte("baz: it's a detail\nwaz\nqux"))
26 ls.Write([]byte("\nfoobar\n"))
27 c.Check(reported, check.DeepEquals, []string{"barbaz", "2021-01-01T00:00:00.000Z: barbaz: it's a detail"})
30 func (s *logScannerSuite) TestOneWritePerLine(c *check.C) {
33 Patterns: []string{"barbaz"},
34 ReportFunc: func(pattern, detail string) {
35 reported = append(reported, pattern, detail)
38 ls.Write([]byte("foo\n"))
39 ls.Write([]byte("2021-01-01T00:00:00.000Z: barbaz: it's a detail\n"))
40 ls.Write([]byte("waz\n"))
41 c.Check(reported, check.DeepEquals, []string{"barbaz", "2021-01-01T00:00:00.000Z: barbaz: it's a detail"})
44 func (s *logScannerSuite) TestNoDetail(c *check.C) {
47 Patterns: []string{"barbaz"},
48 ReportFunc: func(pattern, detail string) {
49 reported = append(reported, pattern, detail)
52 ls.Write([]byte("foo\n"))
53 ls.Write([]byte("barbaz\n"))
54 ls.Write([]byte("waz\n"))
55 c.Check(reported, check.DeepEquals, []string{"barbaz", "barbaz"})