github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/benchmark/internal/cireport/metareport_test.go (about) 1 package cireport_test 2 3 import ( 4 "github.com/pyroscope-io/pyroscope/benchmark/internal/cireport" 5 6 . "github.com/onsi/ginkgo/v2" 7 . "github.com/onsi/gomega" 8 "github.com/pyroscope-io/goldga" 9 ) 10 11 var _ = Describe("metareport", func() { 12 It("generates a markdown report correctly", func() { 13 mr, err := cireport.NewMetaReport([]string{"execution", "seed"}) 14 Expect(err).NotTo(HaveOccurred()) 15 16 report, err := mr.Report("Server Benchmark", []string{"execution=5m", "seed=4"}) 17 Expect(err).ToNot(HaveOccurred()) 18 19 Expect(report).To(goldga.Match()) 20 }) 21 22 Context("error conditions", func() { 23 It("should fail when there are no elements allowed", func() { 24 mr, err := cireport.NewMetaReport([]string{}) 25 26 Expect(err).To(HaveOccurred()) 27 Expect(mr).To(BeNil()) 28 }) 29 30 It("should fail when no element is asked to be reported", func() { 31 mr, err := cireport.NewMetaReport([]string{"allowed"}) 32 Expect(err).NotTo(HaveOccurred()) 33 34 _, err = mr.Report("Server Benchmark", []string{}) 35 Expect(err).To(HaveOccurred()) 36 }) 37 38 It("should fail when an element doesn't pass the allowlist", func() { 39 mr, err := cireport.NewMetaReport([]string{"allowed"}) 40 Expect(err).NotTo(HaveOccurred()) 41 42 _, err = mr.Report("Server Benchmark", []string{"A=B"}) 43 Expect(err).To(HaveOccurred()) 44 }) 45 46 It("only accepts variables in the format A=B", func() { 47 mr, err := cireport.NewMetaReport([]string{"A"}) 48 Expect(err).NotTo(HaveOccurred()) 49 50 _, err = mr.Report("Server Benchmark", []string{"A"}) 51 Expect(err).To(HaveOccurred()) 52 53 _, err = mr.Report("Server Benchmark", []string{"A="}) 54 Expect(err).To(HaveOccurred()) 55 56 _, err = mr.Report("Server Benchmark", []string{"=B"}) 57 Expect(err).To(HaveOccurred()) 58 59 _, err = mr.Report("Server Benchmark", []string{"A=B"}) 60 Expect(err).ToNot(HaveOccurred()) 61 }) 62 }) 63 })