github.com/pf-qiu/concourse/v6@v6.7.3-0.20201207032516-1f455d73275f/fly/integration/containers_test.go (about) 1 package integration_test 2 3 import ( 4 "os/exec" 5 6 "github.com/pf-qiu/concourse/v6/atc" 7 "github.com/pf-qiu/concourse/v6/fly/ui" 8 "github.com/fatih/color" 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("containers", func() { 18 var ( 19 flyCmd *exec.Cmd 20 ) 21 22 BeforeEach(func() { 23 flyCmd = exec.Command(flyPath, "-t", targetName, "containers") 24 }) 25 26 Context("when containers are returned from the API", func() { 27 BeforeEach(func() { 28 atcServer.AppendHandlers( 29 ghttp.CombineHandlers( 30 ghttp.VerifyRequest("GET", "/api/v1/teams/main/containers"), 31 ghttp.RespondWithJSONEncoded(200, []atc.Container{ 32 { 33 ID: "handle-1", 34 WorkerName: "worker-name-1", 35 PipelineID: 1, 36 PipelineName: "instanced-pipeline", 37 PipelineInstanceVars: atc.InstanceVars{"branch": "master"}, 38 Type: "check", 39 ResourceName: "git-repo", 40 }, 41 { 42 ID: "early-handle", 43 WorkerName: "worker-name-1", 44 PipelineName: "pipeline-name", 45 JobName: "job-name-1", 46 BuildName: "3", 47 BuildID: 123, 48 Type: "get", 49 StepName: "git-repo", 50 Attempt: "1.5", 51 }, 52 { 53 ID: "other-handle", 54 WorkerName: "worker-name-2", 55 PipelineName: "pipeline-name", 56 JobName: "job-name-2", 57 BuildName: "2", 58 BuildID: 122, 59 Type: "task", 60 StepName: "unit-tests", 61 }, 62 { 63 ID: "post-handle", 64 WorkerName: "worker-name-3", 65 BuildID: 142, 66 Type: "task", 67 StepName: "one-off", 68 }, 69 }), 70 ), 71 ) 72 }) 73 74 Context("when --json is given", func() { 75 BeforeEach(func() { 76 flyCmd.Args = append(flyCmd.Args, "--json") 77 }) 78 79 It("prints response in json as stdout", func() { 80 sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter) 81 Expect(err).NotTo(HaveOccurred()) 82 83 Eventually(sess).Should(gexec.Exit(0)) 84 Expect(sess.Out.Contents()).To(MatchJSON(`[ 85 { 86 "id": "handle-1", 87 "worker_name": "worker-name-1", 88 "type": "check", 89 "pipeline_id": 1, 90 "pipeline_name": "instanced-pipeline", 91 "pipeline_instance_vars": { 92 "branch": "master" 93 }, 94 "resource_name": "git-repo" 95 }, 96 { 97 "id": "early-handle", 98 "worker_name": "worker-name-1", 99 "type": "get", 100 "step_name": "git-repo", 101 "attempt": "1.5", 102 "build_id": 123, 103 "pipeline_name": "pipeline-name", 104 "job_name": "job-name-1", 105 "build_name": "3" 106 }, 107 { 108 "id": "other-handle", 109 "worker_name": "worker-name-2", 110 "type": "task", 111 "step_name": "unit-tests", 112 "build_id": 122, 113 "pipeline_name": "pipeline-name", 114 "job_name": "job-name-2", 115 "build_name": "2" 116 }, 117 { 118 "id": "post-handle", 119 "worker_name": "worker-name-3", 120 "type": "task", 121 "step_name": "one-off", 122 "build_id": 142 123 } 124 ]`)) 125 }) 126 }) 127 128 It("lists them to the user, ordered by name", func() { 129 sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter) 130 Expect(err).NotTo(HaveOccurred()) 131 132 Eventually(sess).Should(gexec.Exit(0)) 133 Expect(sess.Out).To(PrintTable(ui.Table{ 134 Headers: ui.TableRow{ 135 {Contents: "handle", Color: color.New(color.Bold)}, 136 {Contents: "worker", Color: color.New(color.Bold)}, 137 {Contents: "pipeline", Color: color.New(color.Bold)}, 138 {Contents: "job", Color: color.New(color.Bold)}, 139 {Contents: "build #", Color: color.New(color.Bold)}, 140 {Contents: "build id", Color: color.New(color.Bold)}, 141 {Contents: "type", Color: color.New(color.Bold)}, 142 {Contents: "name", Color: color.New(color.Bold)}, 143 {Contents: "attempt", Color: color.New(color.Bold)}, 144 }, 145 Data: []ui.TableRow{ 146 {{Contents: "early-handle"}, {Contents: "worker-name-1"}, {Contents: "pipeline-name"}, {Contents: "job-name-1"}, {Contents: "3"}, {Contents: "123"}, {Contents: "get"}, {Contents: "git-repo"}, {Contents: "1.5"}}, 147 {{Contents: "handle-1"}, {Contents: "worker-name-1"}, {Contents: "instanced-pipeline/branch:master"}, {Contents: "none", Color: color.New(color.Faint)}, {Contents: "none", Color: color.New(color.Faint)}, {Contents: "none", Color: color.New(color.Faint)}, {Contents: "check"}, {Contents: "git-repo"}, {Contents: "n/a", Color: color.New(color.Faint)}}, 148 {{Contents: "other-handle"}, {Contents: "worker-name-2"}, {Contents: "pipeline-name"}, {Contents: "job-name-2"}, {Contents: "2"}, {Contents: "122"}, {Contents: "task"}, {Contents: "unit-tests"}, {Contents: "n/a", Color: color.New(color.Faint)}}, 149 {{Contents: "post-handle"}, {Contents: "worker-name-3"}, {Contents: "none", Color: color.New(color.Faint)}, {Contents: "none", Color: color.New(color.Faint)}, {Contents: "none", Color: color.New(color.Faint)}, {Contents: "142"}, {Contents: "task"}, {Contents: "one-off"}, {Contents: "n/a", Color: color.New(color.Faint)}}, 150 }, 151 })) 152 }) 153 }) 154 155 Context("and the api returns an internal server error", func() { 156 BeforeEach(func() { 157 atcServer.AppendHandlers( 158 ghttp.CombineHandlers( 159 ghttp.VerifyRequest("GET", "/api/v1/teams/main/containers"), 160 ghttp.RespondWith(500, ""), 161 ), 162 ) 163 }) 164 165 It("writes an error message to stderr", func() { 166 sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter) 167 Expect(err).NotTo(HaveOccurred()) 168 169 Eventually(sess).Should(gexec.Exit(1)) 170 Eventually(sess.Err).Should(gbytes.Say("Unexpected Response")) 171 }) 172 }) 173 }) 174 })