github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/benchmark/internal/cireport/tablereport_test.go (about) 1 package cireport_test 2 3 import ( 4 "context" 5 "fmt" 6 "time" 7 8 "github.com/pyroscope-io/pyroscope/benchmark/internal/cireport" 9 10 . "github.com/onsi/ginkgo/v2" 11 . "github.com/onsi/gomega" 12 "github.com/pyroscope-io/goldga" 13 ) 14 15 type mockQuerier struct { 16 i int 17 respQueryA float64 18 respQueryB float64 19 } 20 21 func (m *mockQuerier) Instant(query string, t time.Time) (float64, error) { 22 fmt.Println(m.i) 23 m.i = m.i + 1 24 fmt.Println(m.i) 25 26 switch m.i { 27 case 1: 28 return m.respQueryA, nil 29 case 2: 30 return m.respQueryB, nil 31 } 32 panic("not implemented") 33 } 34 35 var _ = Describe("tablereport", func() { 36 qc := cireport.QueriesConfig{ 37 BaseName: "base name", 38 TargetName: "target name", 39 Queries: []cireport.Query{ 40 { 41 Name: "my name", 42 Description: "my description", 43 Base: "query_base", 44 Target: "query_target", 45 DiffThreshold: 5, 46 BiggerIsBetter: true, 47 }, 48 }, 49 } 50 51 Context("diff within threshold", func() { 52 It("should generate a report correctly", func() { 53 q := &mockQuerier{ 54 respQueryA: 1, 55 respQueryB: 1, 56 } 57 58 tr := cireport.NewTableReport(q) 59 report, err := tr.Report(context.Background(), &qc) 60 61 Expect(err).ToNot(HaveOccurred()) 62 Expect(report).To(goldga.Match()) 63 }) 64 }) 65 66 Context("diff bigger than threshold", func() { 67 It("should generate a report correctly", func() { 68 q := &mockQuerier{ 69 respQueryA: 0, 70 respQueryB: 2, 71 } 72 73 tr := cireport.NewTableReport(q) 74 report, err := tr.Report(context.Background(), &qc) 75 76 Expect(err).ToNot(HaveOccurred()) 77 Expect(report).To(goldga.Match()) 78 }) 79 }) 80 81 Context("diff smaller than threshold", func() { 82 It("should generate a report correctly", func() { 83 q := &mockQuerier{ 84 respQueryA: 2, 85 respQueryB: 0, 86 } 87 88 tr := cireport.NewTableReport(q) 89 report, err := tr.Report(context.Background(), &qc) 90 91 Expect(err).ToNot(HaveOccurred()) 92 Expect(report).To(goldga.Match()) 93 }) 94 }) 95 })