github.com/chenbh/concourse/v6@v6.4.2/fly/integration/hide_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("hide-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.HidePipeline, 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("hides the pipeline", func() {
    40  					Expect(func() {
    41  						flyCmd := exec.Command(flyPath, "-t", targetName, "hide-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(`hid '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, "hide-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.HidePipeline, 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("hides the pipeline", func() {
   112  					Expect(func() {
   113  						flyCmd := exec.Command(flyPath, "-t", targetName, "hide-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(`hid '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, "hide-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 is not specified", func() {
   163  			It("errors", func() {
   164  				Expect(func() {
   165  					flyCmd := exec.Command(flyPath, "-t", targetName, "hide-pipeline")
   166  
   167  					sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter)
   168  					Expect(err).NotTo(HaveOccurred())
   169  
   170  					<-sess.Exited
   171  					Expect(sess.ExitCode()).To(Equal(1))
   172  				}).To(Change(func() int {
   173  					return len(atcServer.ReceivedRequests())
   174  				}).By(0))
   175  			})
   176  		})
   177  
   178  		Context("when specifying a pipeline name with a '/' character in it", func() {
   179  			It("fails and says '/' characters are not allowed", func() {
   180  				flyCmd := exec.Command(flyPath, "-t", targetName, "hide-pipeline", "-p", "forbidden/pipelinename")
   181  
   182  				sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter)
   183  				Expect(err).NotTo(HaveOccurred())
   184  
   185  				<-sess.Exited
   186  				Expect(sess.ExitCode()).To(Equal(1))
   187  
   188  				Expect(sess.Err).To(gbytes.Say("error: pipeline name cannot contain '/'"))
   189  			})
   190  		})
   191  
   192  	})
   193  })