github.com/chenbh/concourse/v6@v6.4.2/atc/wrappa/concurrent_request_policy_test.go (about) 1 package wrappa_test 2 3 import ( 4 "github.com/chenbh/concourse/v6/atc" 5 "github.com/chenbh/concourse/v6/atc/wrappa" 6 . "github.com/onsi/ginkgo" 7 . "github.com/onsi/gomega" 8 ) 9 10 var _ = Describe("Concurrent Request Policy", func() { 11 Describe("LimitedRoute#UnmarshalFlag", func() { 12 It("unmarshals ListAllJobs", func() { 13 var flagValue wrappa.LimitedRoute 14 flagValue.UnmarshalFlag(atc.ListAllJobs) 15 expected := wrappa.LimitedRoute(atc.ListAllJobs) 16 Expect(flagValue).To(Equal(expected)) 17 }) 18 19 It("raises an error when the action is not supported", func() { 20 var flagValue wrappa.LimitedRoute 21 err := flagValue.UnmarshalFlag(atc.CreateJobBuild) 22 23 expected := "action 'CreateJobBuild' is not supported" 24 Expect(err.Error()).To(ContainSubstring(expected)) 25 }) 26 27 It("error message describes supported actions", func() { 28 var flagValue wrappa.LimitedRoute 29 err := flagValue.UnmarshalFlag(atc.CreateJobBuild) 30 31 expected := "Supported actions are: " 32 Expect(err.Error()).To(ContainSubstring(expected)) 33 }) 34 }) 35 36 Describe("ConcurrentRequestPolicy#HandlerPool", func() { 37 It("returns true when an action is limited", func() { 38 policy := wrappa.NewConcurrentRequestPolicy( 39 map[wrappa.LimitedRoute]int{ 40 wrappa.LimitedRoute(atc.CreateJobBuild): 0, 41 }, 42 ) 43 44 _, found := policy.HandlerPool(atc.CreateJobBuild) 45 Expect(found).To(BeTrue()) 46 }) 47 48 It("returns false when an action is not limited", func() { 49 policy := wrappa.NewConcurrentRequestPolicy( 50 map[wrappa.LimitedRoute]int{ 51 wrappa.LimitedRoute(atc.CreateJobBuild): 0, 52 }, 53 ) 54 55 _, found := policy.HandlerPool(atc.ListAllPipelines) 56 Expect(found).To(BeFalse()) 57 }) 58 59 It("holds a reference to its pool", func() { 60 policy := wrappa.NewConcurrentRequestPolicy( 61 map[wrappa.LimitedRoute]int{ 62 wrappa.LimitedRoute(atc.CreateJobBuild): 1, 63 }, 64 ) 65 pool1, _ := policy.HandlerPool(atc.CreateJobBuild) 66 pool1.TryAcquire() 67 pool2, _ := policy.HandlerPool(atc.CreateJobBuild) 68 Expect(pool2.TryAcquire()).To(BeFalse()) 69 }) 70 }) 71 })