github.com/chenbh/concourse/v6@v6.4.2/atc/wrappa/concourse_version_wrappa_test.go (about) 1 package wrappa_test 2 3 import ( 4 "net/http" 5 6 "github.com/chenbh/concourse/v6/atc" 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("ConcourseVersionWrappa", func() { 15 var ( 16 version string 17 ) 18 19 BeforeEach(func() { 20 version = "1.2.3-test" 21 }) 22 23 versioned := func(handler http.Handler) http.Handler { 24 return wrappa.VersionedHandler{ 25 Version: version, 26 Handler: handler, 27 } 28 } 29 30 Describe("Wrap", func() { 31 var ( 32 inputHandlers rata.Handlers 33 34 expectedHandlers rata.Handlers 35 36 wrappedHandlers rata.Handlers 37 ) 38 39 BeforeEach(func() { 40 inputHandlers = rata.Handlers{} 41 42 for _, route := range atc.Routes { 43 inputHandlers[route.Name] = &stupidHandler{} 44 } 45 46 expectedHandlers = rata.Handlers{} 47 48 // wrap everything 49 for route, handler := range inputHandlers { 50 expectedHandlers[route] = versioned(handler) 51 } 52 }) 53 54 JustBeforeEach(func() { 55 wrappedHandlers = wrappa.NewConcourseVersionWrappa( 56 version, 57 ).Wrap(inputHandlers) 58 }) 59 60 It("wraps every single handler with a version reporting handler", func() { 61 for name, _ := range inputHandlers { 62 Expect(descriptiveRoute{ 63 route: name, 64 handler: wrappedHandlers[name], 65 }).To(Equal(descriptiveRoute{ 66 route: name, 67 handler: expectedHandlers[name], 68 })) 69 } 70 }) 71 }) 72 })