From 1023425c1dc142a197acaa1300c35cad38aeddd1 Mon Sep 17 00:00:00 2001 From: kevin Date: Wed, 7 Oct 2020 23:15:34 +0800 Subject: [PATCH] add more tests --- core/stat/metrics_test.go | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 core/stat/metrics_test.go diff --git a/core/stat/metrics_test.go b/core/stat/metrics_test.go new file mode 100644 index 00000000..a8dd93f4 --- /dev/null +++ b/core/stat/metrics_test.go @@ -0,0 +1,37 @@ +package stat + +import ( + "strconv" + "testing" + "time" + + "github.com/stretchr/testify/assert" +) + +func TestMetrics(t *testing.T) { + counts := []int{1, 5, 10, 100, 1000, 1000} + for _, count := range counts { + m := NewMetrics("foo") + m.SetName("bar") + for i := 0; i < count; i++ { + m.Add(Task{ + Duration: time.Millisecond * time.Duration(i), + Description: strconv.Itoa(i), + }) + } + m.AddDrop() + var writer mockedWriter + SetReportWriter(&writer) + m.executor.Flush() + assert.Equal(t, "bar", writer.report.Name) + } +} + +type mockedWriter struct { + report *StatReport +} + +func (m *mockedWriter) Write(report *StatReport) error { + m.report = report + return nil +}