diff options
| -rw-r--r-- | service_report.go | 1 | ||||
| -rw-r--r-- | service_report_test.go | 14 |
2 files changed, 14 insertions, 1 deletions
diff --git a/service_report.go b/service_report.go index 0959522..a596576 100644 --- a/service_report.go +++ b/service_report.go @@ -62,7 +62,6 @@ func (svcReport *ServiceReport) Close() (err error) { func (svcReport *ServiceReport) Store(scanReport ScanReport) { var record = scanReport.toCSV() - log.Printf(`Store: %v`, record) var err = svcReport.writer.Write(record) if err != nil { log.Printf(`Store: %s`, err) diff --git a/service_report_test.go b/service_report_test.go index 350c7f3..74cf214 100644 --- a/service_report_test.go +++ b/service_report_test.go @@ -4,6 +4,7 @@ package lilin import ( + "bytes" "os" "testing" "time" @@ -33,6 +34,11 @@ func TestServiceReport_Store(t *testing.T) { for x = 1; x <= historyMax+1; x++ { svcReport.Store(ScanReport{At: time.Unix(x, 0)}) } + err = svcReport.Close() + if err != nil { + t.Fatal(err) + } + test.Assert(t, `len(History)`, historyKeepSize, len(svcReport.History)) test.Assert(t, `cap(History)`, historyMax, cap(svcReport.History)) @@ -44,4 +50,12 @@ func TestServiceReport_Store(t *testing.T) { var lastIdx = len(svcReport.History) - 1 gotAtUnix = svcReport.History[lastIdx].At.Unix() test.Assert(t, `History[last].At`, expAtUnix, gotAtUnix) + + var logcontent []byte + logcontent, err = os.ReadFile(svcReport.logPath) + if err != nil { + t.Fatal(err) + } + var lines = bytes.Split(logcontent, []byte("\n")) + test.Assert(t, `log lines length`, historyMax+2, len(lines)) } |
