github.com/pf-qiu/concourse/v6@v6.7.3-0.20201207032516-1f455d73275f/fly/integration/expose_pipeline_test.go (about) 1 package integration_test 2 3 import ( 4 "fmt" 5 "net/http" 6 "os/exec" 7 8 . "github.com/onsi/ginkgo" 9 . "github.com/onsi/gomega" 10 11 "github.com/pf-qiu/concourse/v6/atc" 12 "github.com/onsi/gomega/gbytes" 13 "github.com/onsi/gomega/gexec" 14 "github.com/onsi/gomega/ghttp" 15 "github.com/tedsuo/rata" 16 ) 17 18 var _ = Describe("Fly CLI", func() { 19 Describe("expose-pipeline", func() { 20 Context("when the pipeline name is specified", func() { 21 var ( 22 path string 23 queryParams string 24 err error 25 ) 26 BeforeEach(func() { 27 path, err = atc.Routes.CreatePathForRoute(atc.ExposePipeline, rata.Params{"pipeline_name": "awesome-pipeline", "team_name": "main"}) 28 Expect(err).NotTo(HaveOccurred()) 29 30 queryParams = "instance_vars=%7B%22branch%22%3A%22master%22%7D" 31 }) 32 33 Context("when the pipeline exists", func() { 34 BeforeEach(func() { 35 atcServer.AppendHandlers( 36 ghttp.CombineHandlers( 37 ghttp.VerifyRequest("PUT", path, queryParams), 38 ghttp.RespondWith(http.StatusOK, nil), 39 ), 40 ) 41 }) 42 43 It("exposes the pipeline", func() { 44 Expect(func() { 45 flyCmd := exec.Command(flyPath, "-t", targetName, "expose-pipeline", "-p", "awesome-pipeline/branch:master") 46 47 sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter) 48 Expect(err).NotTo(HaveOccurred()) 49 50 Eventually(sess).Should(gbytes.Say(`exposed 'awesome-pipeline/branch:master'`)) 51 52 <-sess.Exited 53 Expect(sess.ExitCode()).To(Equal(0)) 54 }).To(Change(func() int { 55 return len(atcServer.ReceivedRequests()) 56 }).By(2)) 57 }) 58 }) 59 60 Context("when the pipeline doesn't exist", func() { 61 BeforeEach(func() { 62 atcServer.AppendHandlers( 63 ghttp.CombineHandlers( 64 ghttp.VerifyRequest("PUT", path), 65 ghttp.RespondWith(http.StatusNotFound, nil), 66 ), 67 ) 68 }) 69 70 It("prints helpful message", func() { 71 Expect(func() { 72 flyCmd := exec.Command(flyPath, "-t", targetName, "expose-pipeline", "-p", "awesome-pipeline") 73 74 sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter) 75 Expect(err).NotTo(HaveOccurred()) 76 77 Eventually(sess.Err).Should(gbytes.Say(`pipeline 'awesome-pipeline' not found`)) 78 79 <-sess.Exited 80 Expect(sess.ExitCode()).To(Equal(1)) 81 }).To(Change(func() int { 82 return len(atcServer.ReceivedRequests()) 83 }).By(2)) 84 }) 85 }) 86 }) 87 88 Context("when the pipline name is not specified", func() { 89 It("errors", func() { 90 Expect(func() { 91 flyCmd := exec.Command(flyPath, "-t", targetName, "expose-pipeline") 92 93 sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter) 94 Expect(err).NotTo(HaveOccurred()) 95 96 <-sess.Exited 97 Expect(sess.ExitCode()).To(Equal(1)) 98 }).To(Change(func() int { 99 return len(atcServer.ReceivedRequests()) 100 }).By(0)) 101 }) 102 }) 103 104 Context("when the pipeline flag is invalid", func() { 105 It("fails and print invalid flag error", func() { 106 flyCmd := exec.Command(flyPath, "-t", targetName, "expose-pipeline", "-p", "forbidden/pipelinename") 107 108 sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter) 109 Expect(err).NotTo(HaveOccurred()) 110 111 <-sess.Exited 112 Expect(sess.ExitCode()).To(Equal(1)) 113 114 Expect(sess.Err).To(gbytes.Say("error: invalid argument for flag `" + osFlag("p", "pipeline"))) 115 }) 116 }) 117 118 Context("user is NOT targeting the same team the pipeline belongs to", func() { 119 team := "diff-team" 120 BeforeEach(func() { 121 atcServer.AppendHandlers( 122 ghttp.CombineHandlers( 123 ghttp.VerifyRequest("GET", fmt.Sprintf("/api/v1/teams/%s", team)), 124 ghttp.RespondWithJSONEncoded(http.StatusOK, atc.Team{ 125 Name: team, 126 }), 127 ), 128 ) 129 }) 130 131 Context("when the pipeline name is specified", func() { 132 var ( 133 path string 134 queryParams string 135 err error 136 ) 137 BeforeEach(func() { 138 path, err = atc.Routes.CreatePathForRoute(atc.ExposePipeline, rata.Params{"pipeline_name": "awesome-pipeline", "team_name": team}) 139 Expect(err).NotTo(HaveOccurred()) 140 141 queryParams = "instance_vars=%7B%22branch%22%3A%22master%22%7D" 142 }) 143 144 Context("when the pipeline exists", func() { 145 BeforeEach(func() { 146 atcServer.AppendHandlers( 147 ghttp.CombineHandlers( 148 ghttp.VerifyRequest("PUT", path, queryParams), 149 ghttp.RespondWith(http.StatusOK, nil), 150 ), 151 ) 152 }) 153 154 It("exposes the pipeline", func() { 155 Expect(func() { 156 flyCmd := exec.Command(flyPath, "-t", targetName, "expose-pipeline", "-p", "awesome-pipeline/branch:master", "--team", team) 157 158 sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter) 159 Expect(err).NotTo(HaveOccurred()) 160 161 Eventually(sess).Should(gbytes.Say(`exposed 'awesome-pipeline/branch:master'`)) 162 163 <-sess.Exited 164 Expect(sess.ExitCode()).To(Equal(0)) 165 }).To(Change(func() int { 166 return len(atcServer.ReceivedRequests()) 167 }).By(3)) 168 }) 169 }) 170 171 Context("when the pipeline doesn't exist", func() { 172 BeforeEach(func() { 173 atcServer.AppendHandlers( 174 ghttp.CombineHandlers( 175 ghttp.VerifyRequest("PUT", path), 176 ghttp.RespondWith(http.StatusNotFound, nil), 177 ), 178 ) 179 }) 180 181 It("prints helpful message", func() { 182 Expect(func() { 183 flyCmd := exec.Command(flyPath, "-t", targetName, "expose-pipeline", "-p", "awesome-pipeline", "--team", team) 184 185 sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter) 186 Expect(err).NotTo(HaveOccurred()) 187 188 Eventually(sess.Err).Should(gbytes.Say(`pipeline 'awesome-pipeline' not found`)) 189 190 <-sess.Exited 191 Expect(sess.ExitCode()).To(Equal(1)) 192 }).To(Change(func() int { 193 return len(atcServer.ReceivedRequests()) 194 }).By(3)) 195 }) 196 }) 197 }) 198 }) 199 200 }) 201 })