github.com/chenbh/concourse/v6@v6.4.2/fly/integration/get_pipeline_test.go (about) 1 package integration_test 2 3 import ( 4 "encoding/json" 5 "net/http" 6 "os/exec" 7 8 . "github.com/onsi/ginkgo" 9 . "github.com/onsi/gomega" 10 11 "github.com/onsi/gomega/gbytes" 12 "github.com/onsi/gomega/gexec" 13 "github.com/onsi/gomega/ghttp" 14 "github.com/tedsuo/rata" 15 "sigs.k8s.io/yaml" 16 17 "github.com/chenbh/concourse/v6/atc" 18 ) 19 20 var _ = Describe("Fly CLI", func() { 21 Describe("get-pipeline", func() { 22 var ( 23 config atc.Config 24 ) 25 26 BeforeEach(func() { 27 config = atc.Config{ 28 Groups: atc.GroupConfigs{ 29 { 30 Name: "some-group", 31 Jobs: []string{"job-1", "job-2"}, 32 Resources: []string{"resource-1", "resource-2"}, 33 }, 34 { 35 Name: "some-other-group", 36 Jobs: []string{"job-3", "job-4"}, 37 Resources: []string{"resource-6", "resource-4"}, 38 }, 39 }, 40 41 Resources: atc.ResourceConfigs{ 42 { 43 Name: "some-resource", 44 Type: "some-type", 45 Source: atc.Source{ 46 "source-config": "some-value", 47 }, 48 }, 49 { 50 Name: "some-other-resource", 51 Type: "some-other-type", 52 Source: atc.Source{ 53 "source-config": "some-value", 54 }, 55 }, 56 }, 57 58 ResourceTypes: atc.ResourceTypes{ 59 { 60 Name: "some-resource-type", 61 Type: "some-type", 62 Source: atc.Source{ 63 "source-config": "some-value", 64 }, 65 }, 66 { 67 Name: "some-other-resource-type", 68 Type: "some-other-type", 69 Source: atc.Source{ 70 "source-config": "some-value", 71 }, 72 }, 73 }, 74 75 Jobs: atc.JobConfigs{ 76 { 77 Name: "some-job", 78 Public: true, 79 Serial: true, 80 }, 81 { 82 Name: "some-other-job", 83 }, 84 }, 85 } 86 }) 87 88 Describe("getting", func() { 89 Context("when not specifying a pipeline name", func() { 90 It("fails and says you should give a pipeline name", func() { 91 flyCmd := exec.Command(flyPath, "-t", targetName, "get-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 99 Expect(sess.Err).To(gbytes.Say("error: the required flag `" + osFlag("p", "pipeline") + "' was not specified")) 100 }) 101 }) 102 103 Context("when specifying a pipeline name with a '/' character in it", func() { 104 It("fails and says '/' characters are not allowed", func() { 105 flyCmd := exec.Command(flyPath, "-t", targetName, "get-pipeline", "-p", "forbidden/pipelinename") 106 107 sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter) 108 Expect(err).NotTo(HaveOccurred()) 109 110 <-sess.Exited 111 Expect(sess.ExitCode()).To(Equal(1)) 112 113 Expect(sess.Err).To(gbytes.Say("error: pipeline name cannot contain '/'")) 114 }) 115 }) 116 117 Context("when specifying a pipeline name", func() { 118 var path string 119 BeforeEach(func() { 120 var err error 121 path, err = atc.Routes.CreatePathForRoute(atc.GetConfig, rata.Params{"pipeline_name": "some-pipeline", "team_name": "main"}) 122 Expect(err).NotTo(HaveOccurred()) 123 }) 124 125 Context("and pipeline is not found", func() { 126 JustBeforeEach(func() { 127 atcServer.AppendHandlers( 128 ghttp.CombineHandlers( 129 ghttp.VerifyRequest("GET", path), 130 ghttp.RespondWithJSONEncoded(http.StatusNotFound, ""), 131 ), 132 ) 133 }) 134 135 It("should print pipeline not found error", func() { 136 flyCmd := exec.Command(flyPath, "-t", targetName, "get-pipeline", "--pipeline", "some-pipeline", "-j") 137 138 sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter) 139 Expect(err).NotTo(HaveOccurred()) 140 141 <-sess.Exited 142 Expect(sess.ExitCode()).To(Equal(1)) 143 144 Expect(sess.Err).To(gbytes.Say("error: pipeline not found")) 145 }) 146 }) 147 148 Context("when atc returns valid config", func() { 149 BeforeEach(func() { 150 atcServer.AppendHandlers( 151 ghttp.CombineHandlers( 152 ghttp.VerifyRequest("GET", path), 153 ghttp.RespondWithJSONEncoded(200, atc.ConfigResponse{Config: config}, http.Header{atc.ConfigVersionHeader: {"42"}}), 154 ), 155 ) 156 }) 157 158 It("prints the config as yaml to stdout", func() { 159 flyCmd := exec.Command(flyPath, "-t", targetName, "get-pipeline", "--pipeline", "some-pipeline") 160 161 sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter) 162 Expect(err).NotTo(HaveOccurred()) 163 164 <-sess.Exited 165 Expect(sess.ExitCode()).To(Equal(0)) 166 167 var printedConfig atc.Config 168 err = yaml.Unmarshal(sess.Out.Contents(), &printedConfig) 169 Expect(err).NotTo(HaveOccurred()) 170 171 Expect(printedConfig).To(Equal(config)) 172 }) 173 174 Context("when -j is given", func() { 175 It("prints the config as json to stdout", func() { 176 flyCmd := exec.Command(flyPath, "-t", targetName, "get-pipeline", "--pipeline", "some-pipeline", "-j") 177 178 sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter) 179 Expect(err).NotTo(HaveOccurred()) 180 181 <-sess.Exited 182 Expect(sess.ExitCode()).To(Equal(0)) 183 184 var printedConfig atc.Config 185 err = json.Unmarshal(sess.Out.Contents(), &printedConfig) 186 Expect(err).NotTo(HaveOccurred()) 187 188 Expect(printedConfig).To(Equal(config)) 189 }) 190 }) 191 }) 192 }) 193 }) 194 }) 195 })