github.com/chenbh/concourse/v6@v6.4.2/atc/wrappa/reject_archived_wrappa_test.go (about) 1 package wrappa_test 2 3 import ( 4 "github.com/chenbh/concourse/v6/atc" 5 "github.com/chenbh/concourse/v6/atc/api/pipelineserver" 6 "github.com/chenbh/concourse/v6/atc/db/dbfakes" 7 "github.com/chenbh/concourse/v6/atc/wrappa" 8 "github.com/tedsuo/rata" 9 10 . "github.com/onsi/ginkgo" 11 . "github.com/onsi/gomega" 12 ) 13 14 var _ = Describe("RejectArchivedWrappa", func() { 15 var ( 16 raWrappa *wrappa.RejectArchivedWrappa 17 raHandlerFactory pipelineserver.RejectArchivedHandlerFactory 18 ) 19 20 BeforeEach(func() { 21 fakeTeamFactory := new(dbfakes.FakeTeamFactory) 22 raHandlerFactory = pipelineserver.NewRejectArchivedHandlerFactory(fakeTeamFactory) 23 raWrappa = wrappa.NewRejectArchivedWrappa(raHandlerFactory) 24 }) 25 26 It("wraps endpoints", func() { 27 inputHandlers := rata.Handlers{} 28 29 for _, route := range atc.Routes { 30 inputHandlers[route.Name] = &stupidHandler{} 31 } 32 33 rejectArchivedRoutes := []string{ 34 atc.PausePipeline, 35 atc.UnpausePipeline, 36 atc.CreateJobBuild, 37 atc.ScheduleJob, 38 atc.CheckResource, 39 atc.CheckResourceType, 40 atc.DisableResourceVersion, 41 atc.EnableResourceVersion, 42 atc.PinResourceVersion, 43 atc.UnpinResource, 44 atc.SetPinCommentOnResource, 45 atc.RerunJobBuild, 46 } 47 48 rejectArchivedLookup := make(map[string]bool) 49 for _, name := range rejectArchivedRoutes { 50 rejectArchivedLookup[name] = true 51 } 52 53 wrappedHandlers := raWrappa.Wrap(inputHandlers) 54 55 for name, handler := range inputHandlers { 56 expectedHandler := handler 57 if rejectArchivedLookup[name] { 58 expectedHandler = raHandlerFactory.RejectArchived(expectedHandler) 59 } 60 Expect(wrappedHandlers[name]).To(BeIdenticalTo(expectedHandler), "handler is "+name) 61 } 62 }) 63 64 It("panics on unknown handlers", func() { 65 inputHandlers := rata.Handlers{ 66 "unknownHandler": &stupidHandler{}, 67 } 68 Expect(func() { raWrappa.Wrap(inputHandlers) }).To(PanicWith("how do archived pipelines affect your endpoint?")) 69 }) 70 })