github.com/pf-qiu/concourse/v6@v6.7.3-0.20201207032516-1f455d73275f/fly/integration/volumes_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("volumes", func() { 18 var ( 19 flyCmd *exec.Cmd 20 ) 21 22 BeforeEach(func() { 23 flyCmd = exec.Command(flyPath, "-t", targetName, "volumes") 24 }) 25 26 Context("when volumes are returned from the API", func() { 27 BeforeEach(func() { 28 atcServer.AppendHandlers( 29 ghttp.CombineHandlers( 30 ghttp.VerifyRequest("GET", "/api/v1/teams/main/volumes"), 31 ghttp.RespondWithJSONEncoded(200, []atc.Volume{ 32 { 33 ID: "bbbbbb", 34 WorkerName: "cccccc", 35 Type: "container", 36 ContainerHandle: "container-handle-b", 37 Path: "container-path-b", 38 PipelineID: 1, 39 PipelineName: "pipeline-name", 40 PipelineInstanceVars: atc.InstanceVars{"branch": "master"}, 41 }, 42 { 43 ID: "aaaaaa", 44 WorkerName: "dddddd", 45 Type: "resource", 46 ResourceType: &atc.VolumeResourceType{ 47 ResourceType: &atc.VolumeResourceType{ 48 BaseResourceType: &atc.VolumeBaseResourceType{ 49 Name: "base-resource-type", 50 Version: "base-resource-version", 51 }, 52 Version: atc.Version{"custom": "version"}, 53 }, 54 Version: atc.Version{"a": "b", "c": "d"}, 55 }, 56 }, 57 { 58 ID: "aaabbb", 59 WorkerName: "cccccc", 60 Type: "resource-type", 61 BaseResourceType: &atc.VolumeBaseResourceType{ 62 Name: "base-resource-type", 63 Version: "base-resource-version", 64 }, 65 }, 66 { 67 ID: "eeeeee", 68 WorkerName: "ffffff", 69 Type: "container", 70 ContainerHandle: "container-handle-e", 71 Path: "container-path-e", 72 }, 73 { 74 ID: "ihavenosize", 75 WorkerName: "ffffff", 76 Type: "container", 77 ContainerHandle: "container-handle-i", 78 Path: "container-path-i", 79 ParentHandle: "parent-handle-i", 80 }, 81 { 82 ID: "task-cache-id", 83 WorkerName: "gggggg", 84 Type: "task-cache", 85 PipelineName: "some-pipeline", 86 JobName: "some-job", 87 StepName: "some-step", 88 }, 89 }), 90 ), 91 ) 92 }) 93 94 It("lists them to the user, ordered by worker name and volume name", func() { 95 sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter) 96 Expect(err).NotTo(HaveOccurred()) 97 98 Eventually(sess).Should(gexec.Exit(0)) 99 100 Expect(sess.Out).To(PrintTable(ui.Table{ 101 Headers: ui.TableRow{ 102 {Contents: "handle", Color: color.New(color.Bold)}, 103 {Contents: "worker", Color: color.New(color.Bold)}, 104 {Contents: "type", Color: color.New(color.Bold)}, 105 {Contents: "identifier", Color: color.New(color.Bold)}, 106 }, 107 Data: []ui.TableRow{ 108 { 109 {Contents: "aaabbb"}, 110 {Contents: "cccccc"}, 111 {Contents: "resource-type"}, 112 {Contents: "base-resource-type"}, 113 }, 114 { 115 {Contents: "bbbbbb"}, 116 {Contents: "cccccc"}, 117 {Contents: "container"}, 118 {Contents: "container-handle-b"}, 119 }, 120 { 121 {Contents: "aaaaaa"}, 122 {Contents: "dddddd"}, 123 {Contents: "resource"}, 124 {Contents: "a:b,c:d"}, 125 }, 126 { 127 {Contents: "eeeeee"}, 128 {Contents: "ffffff"}, 129 {Contents: "container"}, 130 {Contents: "container-handle-e"}, 131 }, 132 { 133 {Contents: "ihavenosize"}, 134 {Contents: "ffffff"}, 135 {Contents: "container"}, 136 {Contents: "container-handle-i"}, 137 }, 138 { 139 {Contents: "task-cache-id"}, 140 {Contents: "gggggg"}, 141 {Contents: "task-cache"}, 142 {Contents: "some-pipeline/some-job/some-step"}, 143 }, 144 }, 145 })) 146 }) 147 148 Context("when --json is given", func() { 149 BeforeEach(func() { 150 flyCmd.Args = append(flyCmd.Args, "--json") 151 }) 152 153 It("prints response in json as stdout", func() { 154 sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter) 155 Expect(err).NotTo(HaveOccurred()) 156 157 Eventually(sess).Should(gexec.Exit(0)) 158 Expect(sess.Out.Contents()).To(MatchJSON(`[ 159 { 160 "id": "bbbbbb", 161 "worker_name": "cccccc", 162 "type": "container", 163 "container_handle": "container-handle-b", 164 "path": "container-path-b", 165 "parent_handle": "", 166 "resource_type": null, 167 "base_resource_type": null, 168 "pipeline_id": 1, 169 "pipeline_name": "pipeline-name", 170 "pipeline_instance_vars": { 171 "branch": "master" 172 }, 173 "job_name": "", 174 "step_name": "" 175 }, 176 { 177 "id": "aaaaaa", 178 "worker_name": "dddddd", 179 "type": "resource", 180 "container_handle": "", 181 "path": "", 182 "parent_handle": "", 183 "resource_type": { 184 "resource_type": { 185 "resource_type": null, 186 "base_resource_type": { 187 "name": "base-resource-type", 188 "version": "base-resource-version" 189 }, 190 "version": { 191 "custom": "version" 192 } 193 }, 194 "base_resource_type": null, 195 "version": { 196 "a": "b", 197 "c": "d" 198 } 199 }, 200 "base_resource_type": null, 201 "pipeline_id": 0, 202 "pipeline_name": "", 203 "pipeline_instance_vars": null, 204 "job_name": "", 205 "step_name": "" 206 }, 207 { 208 "id": "aaabbb", 209 "worker_name": "cccccc", 210 "type": "resource-type", 211 "container_handle": "", 212 "path": "", 213 "parent_handle": "", 214 "resource_type": null, 215 "base_resource_type": { 216 "name": "base-resource-type", 217 "version": "base-resource-version" 218 }, 219 "pipeline_id": 0, 220 "pipeline_name": "", 221 "pipeline_instance_vars": null, 222 "job_name": "", 223 "step_name": "" 224 }, 225 { 226 "id": "eeeeee", 227 "worker_name": "ffffff", 228 "type": "container", 229 "container_handle": "container-handle-e", 230 "path": "container-path-e", 231 "parent_handle": "", 232 "resource_type": null, 233 "base_resource_type": null, 234 "pipeline_id": 0, 235 "pipeline_name": "", 236 "pipeline_instance_vars": null, 237 "job_name": "", 238 "step_name": "" 239 }, 240 { 241 "id": "ihavenosize", 242 "worker_name": "ffffff", 243 "type": "container", 244 "container_handle": "container-handle-i", 245 "path": "container-path-i", 246 "parent_handle": "parent-handle-i", 247 "resource_type": null, 248 "base_resource_type": null, 249 "pipeline_id": 0, 250 "pipeline_name": "", 251 "pipeline_instance_vars": null, 252 "job_name": "", 253 "step_name": "" 254 }, 255 { 256 "id": "task-cache-id", 257 "worker_name": "gggggg", 258 "type": "task-cache", 259 "container_handle": "", 260 "path": "", 261 "parent_handle": "", 262 "resource_type": null, 263 "base_resource_type": null, 264 "pipeline_id": 0, 265 "pipeline_name": "some-pipeline", 266 "pipeline_instance_vars": null, 267 "job_name": "some-job", 268 "step_name": "some-step" 269 } 270 ]`)) 271 }) 272 }) 273 274 Context("when --details flag is set", func() { 275 BeforeEach(func() { 276 flyCmd = exec.Command(flyPath, "-t", targetName, "volumes", "--details") 277 }) 278 279 It("displays detailed identifiers", func() { 280 sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter) 281 Expect(err).NotTo(HaveOccurred()) 282 283 Eventually(sess).Should(gexec.Exit(0)) 284 285 Expect(sess.Out).To(PrintTable(ui.Table{ 286 Headers: ui.TableRow{ 287 {Contents: "handle", Color: color.New(color.Bold)}, 288 {Contents: "worker", Color: color.New(color.Bold)}, 289 {Contents: "type", Color: color.New(color.Bold)}, 290 {Contents: "identifier", Color: color.New(color.Bold)}, 291 }, 292 Data: []ui.TableRow{ 293 { 294 {Contents: "aaabbb"}, 295 {Contents: "cccccc"}, 296 {Contents: "resource-type"}, 297 {Contents: "name:base-resource-type,version:base-resource-version"}, 298 }, 299 { 300 {Contents: "bbbbbb"}, 301 {Contents: "cccccc"}, 302 {Contents: "container"}, 303 {Contents: "container:container-handle-b,path:container-path-b"}, 304 }, 305 { 306 {Contents: "aaaaaa"}, 307 {Contents: "dddddd"}, 308 {Contents: "resource"}, 309 {Contents: "type:resource(name:base-resource-type,version:base-resource-version),version:a:b,c:d"}, 310 }, 311 { 312 {Contents: "eeeeee"}, 313 {Contents: "ffffff"}, 314 {Contents: "container"}, 315 {Contents: "container:container-handle-e,path:container-path-e"}, 316 }, 317 { 318 {Contents: "ihavenosize"}, 319 {Contents: "ffffff"}, 320 {Contents: "container"}, 321 {Contents: "container:container-handle-i,path:container-path-i,parent:parent-handle-i"}, 322 }, 323 { 324 {Contents: "task-cache-id"}, 325 {Contents: "gggggg"}, 326 {Contents: "task-cache"}, 327 {Contents: "some-pipeline/some-job/some-step"}, 328 }, 329 }, 330 })) 331 }) 332 }) 333 }) 334 335 Context("and the api returns an internal server error", func() { 336 BeforeEach(func() { 337 atcServer.AppendHandlers( 338 ghttp.CombineHandlers( 339 ghttp.VerifyRequest("GET", "/api/v1/teams/main/volumes"), 340 ghttp.RespondWith(500, ""), 341 ), 342 ) 343 }) 344 345 It("writes an error message to stderr", func() { 346 sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter) 347 Expect(err).NotTo(HaveOccurred()) 348 349 Eventually(sess).Should(gexec.Exit(1)) 350 Eventually(sess.Err).Should(gbytes.Say("Unexpected Response")) 351 }) 352 }) 353 }) 354 })