github.com/chenbh/concourse/v6@v6.4.2/fly/integration/expose_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("expose-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.ExposePipeline, rata.Params{"pipeline_name": "awesome-pipeline", "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.VerifyRequest("PUT", path),
    34  							ghttp.RespondWith(http.StatusOK, nil),
    35  						),
    36  					)
    37  				})
    38  
    39  				It("exposes the pipeline", func() {
    40  					Expect(func() {
    41  						flyCmd := exec.Command(flyPath, "-t", targetName, "expose-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(`exposed '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, "expose-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 the pipline name is not specified", func() {
    85  			It("errors", func() {
    86  				Expect(func() {
    87  					flyCmd := exec.Command(flyPath, "-t", targetName, "expose-pipeline")
    88  
    89  					sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter)
    90  					Expect(err).NotTo(HaveOccurred())
    91  
    92  					<-sess.Exited
    93  					Expect(sess.ExitCode()).To(Equal(1))
    94  				}).To(Change(func() int {
    95  					return len(atcServer.ReceivedRequests())
    96  				}).By(0))
    97  			})
    98  		})
    99  
   100  		Context("when specifying a pipeline name with a '/' character in it", func() {
   101  			It("fails and says '/' characters are not allowed", func() {
   102  				flyCmd := exec.Command(flyPath, "-t", targetName, "expose-pipeline", "-p", "forbidden/pipelinename")
   103  
   104  				sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter)
   105  				Expect(err).NotTo(HaveOccurred())
   106  
   107  				<-sess.Exited
   108  				Expect(sess.ExitCode()).To(Equal(1))
   109  
   110  				Expect(sess.Err).To(gbytes.Say("error: pipeline name cannot contain '/'"))
   111  			})
   112  		})
   113  
   114  	})
   115  })