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