Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kevwan committed Oct 7, 2020
1 parent 360fbfd commit 1023425
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions core/stat/metrics_test.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 1023425

Please sign in to comment.