github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/pkg/model/annotation_test.go (about) 1 package model_test 2 3 import ( 4 . "github.com/onsi/ginkgo/v2" 5 . "github.com/onsi/gomega" 6 "github.com/pyroscope-io/pyroscope/pkg/model" 7 ) 8 9 var _ = Describe("Annotation", func() { 10 Describe("CreateAnnotation", func() { 11 When("required fields are missing", func() { 12 It("fails with multiple errors", func() { 13 m := model.CreateAnnotation{} 14 Expect(m.Parse()).To(MatchError(model.ErrAnnotationInvalidAppName)) 15 Expect(m.Parse()).To(MatchError(model.ErrAnnotationInvalidContent)) 16 }) 17 }) 18 19 When("timestamp is absent", func() { 20 It("defaults to time.Now()", func() { 21 m := model.CreateAnnotation{ 22 AppName: "myappname", 23 Content: "mycontent", 24 } 25 Expect(m.Parse()).ToNot(HaveOccurred()) 26 27 // Instead of mocking time.Now, it's easier to just assert it's not zero 28 Expect(m.Timestamp).ToNot(BeZero()) 29 }) 30 }) 31 32 When("appName contains tags", func() { 33 It("errors", func() { 34 m := model.CreateAnnotation{ 35 AppName: `myappname{my="tag"}`, 36 Content: "mycontent", 37 } 38 Expect(m.Parse()).ToNot(HaveOccurred()) 39 Expect(m.AppName).To(Equal("myappname")) 40 }) 41 }) 42 43 When("appName is a query without name", func() { 44 It("errors", func() { 45 m := model.CreateAnnotation{ 46 AppName: `{my="tag"}`, 47 Content: "mycontent", 48 } 49 err := m.Parse() 50 Expect(err).To(MatchError(model.ErrAnnotationInvalidAppName)) 51 }) 52 }) 53 }) 54 })