github.com/chenbh/concourse/v6@v6.4.2/fly/integration/ordering_pipelines_test.go (about) 1 package integration_test 2 3 import ( 4 "net/http" 5 "os/exec" 6 7 . "github.com/onsi/ginkgo" 8 . "github.com/onsi/gomega" 9 10 "github.com/chenbh/concourse/v6/atc" 11 "github.com/onsi/gomega/gbytes" 12 "github.com/onsi/gomega/gexec" 13 "github.com/onsi/gomega/ghttp" 14 "github.com/tedsuo/rata" 15 ) 16 17 var _ = Describe("Fly CLI", func() { 18 Describe("ordering-pipeline", func() { 19 Context("when pipeline names are specified", func() { 20 var ( 21 path string 22 err error 23 ) 24 BeforeEach(func() { 25 path, err = atc.Routes.CreatePathForRoute(atc.OrderPipelines, rata.Params{"team_name": "main"}) 26 Expect(err).NotTo(HaveOccurred()) 27 }) 28 29 Context("when the pipeline exists", func() { 30 BeforeEach(func() { 31 atcServer.AppendHandlers( 32 ghttp.CombineHandlers( 33 ghttp.VerifyJSONRepresenting([]string{"awesome-pipeline", "awesome-pipeline-2"}), 34 ghttp.VerifyRequest("PUT", path), 35 ghttp.RespondWith(http.StatusOK, nil), 36 ), 37 ) 38 }) 39 40 It("orders the pipeline", func() { 41 Expect(func() { 42 flyCmd := exec.Command(flyPath, "-t", targetName, "order-pipelines", "-p", "awesome-pipeline", "-p", "awesome-pipeline-2") 43 44 sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter) 45 Expect(err).NotTo(HaveOccurred()) 46 47 <-sess.Exited 48 Expect(sess.ExitCode()).To(Equal(0)) 49 Eventually(sess).Should(gbytes.Say(`ordered pipelines`)) 50 Eventually(sess).Should(gbytes.Say(` - awesome-pipeline`)) 51 Eventually(sess).Should(gbytes.Say(` - awesome-pipeline-2`)) 52 53 }).To(Change(func() int { 54 return len(atcServer.ReceivedRequests()) 55 }).By(2)) 56 }) 57 58 It("orders the pipeline with alias", func() { 59 Expect(func() { 60 flyCmd := exec.Command(flyPath, "-t", targetName, "op", "-p", "awesome-pipeline", "-p", "awesome-pipeline-2") 61 62 sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter) 63 Expect(err).NotTo(HaveOccurred()) 64 65 <-sess.Exited 66 Expect(sess.ExitCode()).To(Equal(0)) 67 Eventually(sess).Should(gbytes.Say(`ordered pipelines`)) 68 Eventually(sess).Should(gbytes.Say(` - awesome-pipeline`)) 69 Eventually(sess).Should(gbytes.Say(` - awesome-pipeline-2`)) 70 71 }).To(Change(func() int { 72 return len(atcServer.ReceivedRequests()) 73 }).By(2)) 74 }) 75 }) 76 77 Context("when the alphabetical option is passed", func() { 78 BeforeEach(func() { 79 atcServer.AppendHandlers( 80 ghttp.CombineHandlers( 81 ghttp.VerifyRequest("GET", "/api/v1/teams/main/pipelines"), 82 ghttp.RespondWithJSONEncoded(200, []atc.Pipeline{ 83 {Name: "beautiful-pipeline", Paused: false, Public: false}, 84 {Name: "awesome-pipeline", Paused: true, Public: false}, 85 {Name: "delightful-pipeline", Paused: false, Public: true}, 86 {Name: "charming-pipeline", Paused: false, Public: true}, 87 }), 88 ), 89 ghttp.CombineHandlers( 90 ghttp.VerifyRequest("PUT", path), 91 ghttp.RespondWith(http.StatusOK, nil), 92 ), 93 ) 94 }) 95 96 It("orders all the pipelines in alphabetical order", func() { 97 Expect(func() { 98 flyCmd := exec.Command(flyPath, "-t", targetName, "order-pipelines", "--alphabetical") 99 100 sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter) 101 Expect(err).NotTo(HaveOccurred()) 102 103 <-sess.Exited 104 Expect(sess.ExitCode()).To(Equal(0)) 105 Eventually(sess).Should(gbytes.Say(`ordered pipelines`)) 106 Eventually(sess).Should(gbytes.Say(` - awesome-pipeline`)) 107 Eventually(sess).Should(gbytes.Say(` - beautiful-pipeline`)) 108 Eventually(sess).Should(gbytes.Say(` - charming-pipeline`)) 109 Eventually(sess).Should(gbytes.Say(` - delightful-pipeline`)) 110 111 }).To(Change(func() int { 112 return len(atcServer.ReceivedRequests()) 113 }).By(3)) 114 }) 115 }) 116 117 Context("when the pipeline doesn't exist", func() { 118 BeforeEach(func() { 119 atcServer.AppendHandlers( 120 ghttp.CombineHandlers( 121 ghttp.VerifyRequest("PUT", path), 122 ghttp.RespondWith(http.StatusInternalServerError, nil), 123 ), 124 ) 125 }) 126 127 It("prints error message", func() { 128 Expect(func() { 129 flyCmd := exec.Command(flyPath, "-t", targetName, "order-pipelines", "-p", "awesome-pipeline") 130 131 sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter) 132 Expect(err).NotTo(HaveOccurred()) 133 134 <-sess.Exited 135 Expect(sess.ExitCode()).To(Equal(1)) 136 Eventually(sess.Err).Should(gbytes.Say(`failed to order pipelines`)) 137 138 }).To(Change(func() int { 139 return len(atcServer.ReceivedRequests()) 140 }).By(2)) 141 }) 142 }) 143 }) 144 145 Context("when the pipline name is not specified", func() { 146 It("errors", func() { 147 Expect(func() { 148 flyCmd := exec.Command(flyPath, "-t", targetName, "order-pipelines") 149 150 sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter) 151 Expect(err).NotTo(HaveOccurred()) 152 153 <-sess.Exited 154 Expect(sess.ExitCode()).To(Equal(1)) 155 Expect(sess.Err).Should(gbytes.Say("error: either --pipeline or --alphabetical are required")) 156 }).To(Change(func() int { 157 return len(atcServer.ReceivedRequests()) 158 }).By(0)) 159 }) 160 }) 161 162 Context("when specifying a pipeline name with a '/' character in it", func() { 163 It("fails and says '/' characters are not allowed", func() { 164 flyCmd := exec.Command(flyPath, "-t", targetName, "order-pipelines", "-p", "forbidden/pipelinename") 165 166 sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter) 167 Expect(err).NotTo(HaveOccurred()) 168 169 <-sess.Exited 170 Expect(sess.ExitCode()).To(Equal(1)) 171 172 Expect(sess.Err).To(gbytes.Say("error: pipeline name cannot contain '/'")) 173 }) 174 }) 175 176 }) 177 })