github.com/chenbh/concourse/v6@v6.4.2/fly/integration/unpause_pipeline_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("unpause-pipeline", func() { 19 Context("when the pipeline name is specified", func() { 20 var ( 21 mainPath string 22 otherPath string 23 err error 24 ) 25 BeforeEach(func() { 26 mainPath, err = atc.Routes.CreatePathForRoute(atc.UnpausePipeline, rata.Params{"pipeline_name": "awesome-pipeline", "team_name": "main"}) 27 Expect(err).NotTo(HaveOccurred()) 28 29 otherPath, err = atc.Routes.CreatePathForRoute(atc.UnpausePipeline, rata.Params{"pipeline_name": "awesome-pipeline", "team_name": "other-team"}) 30 Expect(err).NotTo(HaveOccurred()) 31 }) 32 33 Context("when the pipeline exists", func() { 34 35 Context("user and pipeline are part of the main team", func() { 36 Context("user is targeting the same team the pipeline belongs to", func() { 37 BeforeEach(func() { 38 atcServer.AppendHandlers( 39 ghttp.CombineHandlers( 40 ghttp.VerifyRequest("PUT", mainPath), 41 ghttp.RespondWith(http.StatusOK, nil), 42 ), 43 ) 44 }) 45 46 It("unpauses the pipeline", func() { 47 Expect(func() { 48 flyCmd := exec.Command(flyPath, "-t", targetName, "unpause-pipeline", "-p", "awesome-pipeline") 49 50 sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter) 51 Expect(err).NotTo(HaveOccurred()) 52 53 Eventually(sess).Should(gbytes.Say(`unpaused 'awesome-pipeline'`)) 54 55 <-sess.Exited 56 Expect(sess.ExitCode()).To(Equal(0)) 57 }).To(Change(func() int { 58 return len(atcServer.ReceivedRequests()) 59 }).By(2)) 60 }) 61 }) 62 63 Context("user is NOT targeting the same team the pipeline belongs to", func() { 64 BeforeEach(func() { 65 atcServer.AppendHandlers( 66 ghttp.CombineHandlers( 67 ghttp.VerifyRequest("GET", "/api/v1/teams/other-team"), 68 ghttp.RespondWithJSONEncoded(http.StatusOK, atc.Team{ 69 Name: "other-team", 70 }), 71 ), 72 ghttp.CombineHandlers( 73 ghttp.VerifyRequest("PUT", otherPath), 74 ghttp.RespondWith(http.StatusOK, nil), 75 ), 76 ) 77 }) 78 79 It("unpauses the pipeline", func() { 80 flyCmd := exec.Command(flyPath, "-t", targetName, "unpause-pipeline", "-p", "awesome-pipeline", "--team", "other-team") 81 82 sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter) 83 Expect(err).NotTo(HaveOccurred()) 84 85 Eventually(sess).Should(gbytes.Say(`unpaused 'awesome-pipeline'`)) 86 87 <-sess.Exited 88 Expect(sess.ExitCode()).To(Equal(0)) 89 }) 90 }) 91 92 }) 93 94 }) 95 96 Context("when the pipeline doesn't exist", func() { 97 BeforeEach(func() { 98 atcServer.AppendHandlers( 99 ghttp.CombineHandlers( 100 ghttp.VerifyRequest("PUT", mainPath), 101 ghttp.RespondWith(http.StatusNotFound, nil), 102 ), 103 ) 104 }) 105 106 It("prints helpful message", func() { 107 Expect(func() { 108 flyCmd := exec.Command(flyPath, "-t", targetName, "unpause-pipeline", "-p", "awesome-pipeline") 109 110 sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter) 111 Expect(err).NotTo(HaveOccurred()) 112 113 Eventually(sess.Err).Should(gbytes.Say(`pipeline 'awesome-pipeline' not found`)) 114 115 <-sess.Exited 116 Expect(sess.ExitCode()).To(Equal(1)) 117 }).To(Change(func() int { 118 return len(atcServer.ReceivedRequests()) 119 }).By(2)) 120 }) 121 }) 122 }) 123 124 Context("when the pipline name or --all is not specified", func() { 125 It("errors", func() { 126 Expect(func() { 127 flyCmd := exec.Command(flyPath, "-t", targetName, "unpause-pipeline") 128 129 sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter) 130 Expect(err).NotTo(HaveOccurred()) 131 132 Eventually(sess.Err).Should(gbytes.Say(`one of the flags '-p, --pipeline' or '-a, --all' is required`)) 133 134 <-sess.Exited 135 Expect(sess.ExitCode()).To(Equal(1)) 136 }).To(Change(func() int { 137 return len(atcServer.ReceivedRequests()) 138 }).By(0)) 139 }) 140 }) 141 142 Context("when both the pipline name and --all are specified", func() { 143 It("errors", func() { 144 Expect(func() { 145 flyCmd := exec.Command(flyPath, "-t", targetName, "unpause-pipeline", "-p", "awesome-pipeline", "--all") 146 147 sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter) 148 Expect(err).NotTo(HaveOccurred()) 149 150 Eventually(sess.Err).Should(gbytes.Say(`only one of the flags '-p, --pipeline' or '-a, --all' is allowed`)) 151 152 <-sess.Exited 153 Expect(sess.ExitCode()).To(Equal(1)) 154 }).To(Change(func() int { 155 return len(atcServer.ReceivedRequests()) 156 }).By(0)) 157 }) 158 }) 159 160 Context("when specifying a pipeline name with a '/' character in it", func() { 161 It("fails and says '/' characters are not allowed", func() { 162 flyCmd := exec.Command(flyPath, "-t", targetName, "unpause-pipeline", "-p", "forbidden/pipelinename") 163 164 sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter) 165 Expect(err).NotTo(HaveOccurred()) 166 167 <-sess.Exited 168 Expect(sess.ExitCode()).To(Equal(1)) 169 170 Expect(sess.Err).To(gbytes.Say("error: pipeline name cannot contain '/'")) 171 }) 172 }) 173 174 }) 175 Context("when the --all flag is passed", func() { 176 var ( 177 somePath string 178 someOtherPath string 179 err error 180 ) 181 182 BeforeEach(func() { 183 somePath, err = atc.Routes.CreatePathForRoute(atc.UnpausePipeline, rata.Params{"pipeline_name": "awesome-pipeline", "team_name": "main"}) 184 Expect(err).NotTo(HaveOccurred()) 185 186 someOtherPath, err = atc.Routes.CreatePathForRoute(atc.UnpausePipeline, rata.Params{"pipeline_name": "more-awesome-pipeline", "team_name": "main"}) 187 Expect(err).NotTo(HaveOccurred()) 188 189 atcServer.AppendHandlers( 190 ghttp.CombineHandlers( 191 ghttp.VerifyRequest("GET", "/api/v1/teams/main/pipelines"), 192 ghttp.RespondWithJSONEncoded(200, []atc.Pipeline{ 193 {Name: "awesome-pipeline", Paused: false, Public: false}, 194 {Name: "more-awesome-pipeline", Paused: true, Public: false}, 195 }), 196 ), 197 ghttp.CombineHandlers( 198 ghttp.VerifyRequest("PUT", somePath), 199 ghttp.RespondWith(http.StatusOK, nil), 200 ), 201 ghttp.CombineHandlers( 202 ghttp.VerifyRequest("PUT", someOtherPath), 203 ghttp.RespondWith(http.StatusOK, nil), 204 ), 205 ) 206 }) 207 208 It("unpauses every pipeline", func() { 209 Expect(func() { 210 flyCmd := exec.Command(flyPath, "-t", targetName, "unpause-pipeline", "--all") 211 212 sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter) 213 Expect(err).NotTo(HaveOccurred()) 214 215 Eventually(sess).Should(gbytes.Say(`unpaused 'awesome-pipeline'`)) 216 Eventually(sess).Should(gbytes.Say(`unpaused 'more-awesome-pipeline'`)) 217 218 <-sess.Exited 219 Expect(sess.ExitCode()).To(Equal(0)) 220 }).To(Change(func() int { 221 return len(atcServer.ReceivedRequests()) 222 }).By(4)) 223 }) 224 225 }) 226 })