github.com/chenbh/concourse/v6@v6.4.2/fly/integration/checklist_test.go (about) 1 package integration_test 2 3 import ( 4 "fmt" 5 "net/http" 6 "os" 7 "os/exec" 8 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 "github.com/chenbh/concourse/v6/atc" 16 ) 17 18 var _ = Describe("Fly CLI", func() { 19 Describe("checklist", func() { 20 var ( 21 config atc.Config 22 home string 23 ) 24 25 BeforeEach(func() { 26 config = atc.Config{ 27 Groups: atc.GroupConfigs{ 28 { 29 Name: "some-group", 30 Jobs: []string{"job-1", "job-2"}, 31 Resources: []string{"resource-1", "resource-2"}, 32 }, 33 { 34 Name: "some-other-group", 35 Jobs: []string{"job-3", "job-4"}, 36 Resources: []string{"resource-6", "resource-4"}, 37 }, 38 }, 39 40 Jobs: atc.JobConfigs{ 41 { 42 Name: "some-orphaned-job", 43 }, 44 }, 45 } 46 }) 47 48 AfterEach(func() { 49 err := os.RemoveAll(home) 50 Expect(err).NotTo(HaveOccurred()) 51 }) 52 53 Context("when a pipeline name is not specified", func() { 54 It("errors", func() { 55 flyCmd := exec.Command(flyPath, "-t", targetName, "checklist") 56 57 sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter) 58 Expect(err).NotTo(HaveOccurred()) 59 60 <-sess.Exited 61 Expect(sess.ExitCode()).To(Equal(1)) 62 }) 63 }) 64 65 Context("when specifying a pipeline name with a '/' character in it", func() { 66 It("fails and says '/' characters are not allowed", func() { 67 flyCmd := exec.Command(flyPath, "-t", targetName, "checklist", "-p", "forbidden/pipelinename") 68 69 sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter) 70 Expect(err).NotTo(HaveOccurred()) 71 72 <-sess.Exited 73 Expect(sess.ExitCode()).To(Equal(1)) 74 75 Expect(sess.Err).To(gbytes.Say("error: pipeline name cannot contain '/'")) 76 }) 77 }) 78 79 Context("when a pipeline name is specified", func() { 80 JustBeforeEach(func() { 81 atcServer.AppendHandlers( 82 ghttp.CombineHandlers( 83 ghttp.VerifyRequest("GET", "/api/v1/teams/main/pipelines/some-pipeline/config"), 84 ghttp.RespondWithJSONEncoded(200, atc.ConfigResponse{Config: config}, http.Header{atc.ConfigVersionHeader: {"42"}}), 85 ), 86 ) 87 }) 88 89 Context("when there are groups", func() { 90 It("prints the config as yaml to stdout", func() { 91 flyCmd := exec.Command(flyPath, "-t", targetName, "checklist", "-p", "some-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(0)) 98 99 Expect(string(sess.Out.Contents())).To(Equal(fmt.Sprintf( 100 `#- some-group 101 job-1: concourse.check %s main some-pipeline job-1 102 job-2: concourse.check %s main some-pipeline job-2 103 104 #- some-other-group 105 job-3: concourse.check %s main some-pipeline job-3 106 job-4: concourse.check %s main some-pipeline job-4 107 108 #- misc 109 some-orphaned-job: concourse.check %s main some-pipeline some-orphaned-job 110 111 `, atcServer.URL(), atcServer.URL(), atcServer.URL(), atcServer.URL(), atcServer.URL()))) 112 }) 113 }) 114 115 Context("when there are no groups", func() { 116 BeforeEach(func() { 117 config = atc.Config{ 118 Jobs: atc.JobConfigs{ 119 { 120 Name: "job-1", 121 }, 122 { 123 Name: "job-2", 124 }, 125 }, 126 } 127 128 }) 129 130 It("prints the config as yaml to stdout, and uses the pipeline name as header", func() { 131 flyCmd := exec.Command(flyPath, "-t", targetName, "checklist", "-p", "some-pipeline") 132 133 sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter) 134 Expect(err).NotTo(HaveOccurred()) 135 136 <-sess.Exited 137 Expect(sess.ExitCode()).To(Equal(0)) 138 139 Expect(string(sess.Out.Contents())).To(Equal(fmt.Sprintf( 140 `#- some-pipeline 141 job-1: concourse.check %s main some-pipeline job-1 142 job-2: concourse.check %s main some-pipeline job-2 143 144 `, atcServer.URL(), atcServer.URL()))) 145 }) 146 }) 147 }) 148 }) 149 })