aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2025-08-28 21:42:14 +0700
committerShulhan <ms@kilabit.info>2025-08-28 21:42:26 +0700
commit4e309ddeaebb06512ddb1473ec2207b4ad2c0a0b (patch)
tree29e27c2f808dcf773c418796ae8800ada5dcb5c2
parentc274821a1f2990a89bd682bc07252311e61a9a7c (diff)
downloadlilin-4e309ddeaebb06512ddb1473ec2207b4ad2c0a0b.tar.xz
all: close the ServiceReport when testing Store
While at it, remove logging on Store.
-rw-r--r--service_report.go1
-rw-r--r--service_report_test.go14
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))
}