github.com/pingcap/br@v5.3.0-alpha.0.20220125034240-ec59c7b6ce30+incompatible/pkg/summary/collector_test.go (about) 1 // Copyright 2020 PingCAP, Inc. Licensed under Apache-2.0. 2 3 package summary 4 5 import ( 6 "testing" 7 "time" 8 9 . "github.com/pingcap/check" 10 "go.uber.org/zap" 11 ) 12 13 func TestT(t *testing.T) { 14 TestingT(t) 15 } 16 17 var _ = Suite(&testCollectorSuite{}) 18 19 type testCollectorSuite struct { 20 } 21 22 func (suit *testCollectorSuite) TestSumDurationInt(c *C) { 23 fields := []zap.Field{} 24 logger := func(msg string, fs ...zap.Field) { 25 fields = append(fields, fs...) 26 } 27 col := NewLogCollector(logger) 28 col.CollectDuration("a", time.Second) 29 col.CollectDuration("b", time.Second) 30 col.CollectDuration("b", time.Second) 31 col.CollectInt("c", 2) 32 col.CollectInt("c", 2) 33 col.SetSuccessStatus(true) 34 col.Summary("foo") 35 36 c.Assert(len(fields), Equals, 7) 37 assertContains := func(field zap.Field) { 38 for _, f := range fields { 39 if f.Key == field.Key { 40 c.Assert(f, DeepEquals, field) 41 return 42 } 43 } 44 c.Error(fields, "do not contain", field) 45 } 46 assertContains(zap.Duration("a", time.Second)) 47 assertContains(zap.Duration("b", 2*time.Second)) 48 assertContains(zap.Int("c", 4)) 49 }