github.com/chenbh/concourse/v6@v6.4.2/fly/integration/unpause_job_test.go (about)

     1  package integration_test
     2  
     3  import (
     4  	"fmt"
     5  	"net/http"
     6  	"os/exec"
     7  
     8  	"github.com/chenbh/concourse/v6/atc"
     9  	. "github.com/onsi/ginkgo"
    10  	. "github.com/onsi/gomega"
    11  	"github.com/onsi/gomega/gbytes"
    12  	"github.com/onsi/gomega/gexec"
    13  	"github.com/onsi/gomega/ghttp"
    14  )
    15  
    16  var _ = Describe("Fly CLI", func() {
    17  	Describe("Unpause Job", func() {
    18  		var (
    19  			flyCmd       *exec.Cmd
    20  			pipelineName string
    21  			jobName      string
    22  			fullJobName  string
    23  			apiPath      string
    24  		)
    25  
    26  		BeforeEach(func() {
    27  			pipelineName = "pipeline"
    28  			jobName = "job-name-potato"
    29  			fullJobName = fmt.Sprintf("%s/%s", pipelineName, jobName)
    30  			apiPath = fmt.Sprintf("/api/v1/teams/main/pipelines/%s/jobs/%s/unpause", pipelineName, jobName)
    31  
    32  			flyCmd = exec.Command(flyPath, "-t", targetName, "unpause-job", "-j", fullJobName)
    33  		})
    34  
    35  		Context("when the job flag is provided", func() {
    36  			Context("when user and pipeline belong to the same team", func() {
    37  				Context("user is targeting the same team that the pipeline belongs to", func() {
    38  					BeforeEach(func() {
    39  						atcServer.AppendHandlers(
    40  							ghttp.CombineHandlers(
    41  								ghttp.VerifyRequest("PUT", apiPath),
    42  								ghttp.RespondWith(http.StatusOK, nil),
    43  							),
    44  						)
    45  					})
    46  
    47  					It("successfully unpauses the job", func() {
    48  						sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter)
    49  						Expect(err).NotTo(HaveOccurred())
    50  
    51  						<-sess.Exited
    52  						Expect(sess.ExitCode()).To(Equal(0))
    53  						Eventually(sess).Should(gbytes.Say(fmt.Sprintf("unpaused '%s'\n", jobName)))
    54  					})
    55  				})
    56  
    57  				Context("user is NOT targeting the same team that the pipeline belongs to", func() {
    58  					BeforeEach(func() {
    59  						apiPath = fmt.Sprintf("/api/v1/teams/other-team/pipelines/%s/jobs/%s/unpause", pipelineName, jobName)
    60  
    61  						atcServer.AppendHandlers(
    62  							ghttp.CombineHandlers(
    63  								ghttp.VerifyRequest("GET", "/api/v1/teams/other-team"),
    64  								ghttp.RespondWithJSONEncoded(http.StatusOK, atc.Team{
    65  									Name: "other-team",
    66  								}),
    67  							),
    68  							ghttp.CombineHandlers(
    69  								ghttp.VerifyRequest("PUT", apiPath),
    70  								ghttp.RespondWith(http.StatusOK, nil),
    71  							),
    72  						)
    73  					})
    74  
    75  					It("successfully unpauses the job", func() {
    76  						flyCmd = exec.Command(flyPath, "-t", targetName, "unpause-job", "-j", fullJobName, "--team", "other-team")
    77  						sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter)
    78  						Expect(err).NotTo(HaveOccurred())
    79  						<-sess.Exited
    80  						Expect(sess.ExitCode()).To(Equal(0))
    81  						Eventually(sess).Should(gbytes.Say(fmt.Sprintf("unpaused '%s'\n", jobName)))
    82  					})
    83  				})
    84  			})
    85  
    86  			Context("when unpause-job fails", func() {
    87  				BeforeEach(func() {
    88  					apiPath := fmt.Sprintf("/api/v1/teams/main/pipelines/%s/jobs/%s/unpause", pipelineName, jobName)
    89  					atcServer.AppendHandlers(
    90  						ghttp.CombineHandlers(
    91  							ghttp.VerifyRequest("PUT", apiPath),
    92  							ghttp.RespondWith(http.StatusInternalServerError, nil),
    93  						),
    94  					)
    95  				})
    96  
    97  				It("exits 1 and outputs an error", func() {
    98  					sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter)
    99  					Expect(err).NotTo(HaveOccurred())
   100  
   101  					Eventually(sess.Err).Should(gbytes.Say(`error`))
   102  
   103  					<-sess.Exited
   104  					Expect(sess.ExitCode()).To(Equal(1))
   105  				})
   106  			})
   107  		})
   108  
   109  		Context("when the job flag is not provided", func() {
   110  			BeforeEach(func() {
   111  				flyCmd = exec.Command(flyPath, "-t", targetName, "unpause-job")
   112  			})
   113  
   114  			It("exits 1 and outputs an error", func() {
   115  				sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter)
   116  				Expect(err).NotTo(HaveOccurred())
   117  
   118  				Eventually(sess.Err).Should(gbytes.Say(`error`))
   119  
   120  				<-sess.Exited
   121  				Expect(sess.ExitCode()).To(Equal(1))
   122  			})
   123  		})
   124  	})
   125  })