github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/pkg/agent/target/target_test.go (about) 1 //go:build debugspy 2 // +build debugspy 3 4 package target 5 6 import ( 7 "context" 8 "time" 9 10 . "github.com/onsi/ginkgo/v2" 11 . "github.com/onsi/gomega" 12 "github.com/sirupsen/logrus" 13 14 "github.com/pyroscope-io/pyroscope/pkg/agent/upstream/remote" 15 "github.com/pyroscope-io/pyroscope/pkg/config" 16 ) 17 18 type fakeTarget struct{ attached int } 19 20 func (t *fakeTarget) attach(_ context.Context) { t.attached++ } 21 22 var _ = Describe("target", func() { 23 It("Attaches to targets", func() { 24 tgtMgr := NewManager(logrus.StandardLogger(), new(remote.Remote), &config.Agent{ 25 Targets: []config.Target{ 26 { 27 ServiceName: "my-service", 28 SpyName: "debugspy", 29 ApplicationName: "my.app", 30 }, 31 }, 32 }) 33 34 t := new(fakeTarget) 35 tgtMgr.resolve = func(c config.Target) (target, bool) { return t, true } 36 tgtMgr.backoffPeriod = time.Millisecond * 10 37 38 tgtMgr.Start() 39 time.Sleep(time.Second) 40 tgtMgr.Stop() 41 42 Expect(t.attached).ToNot(BeZero()) 43 }) 44 })