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