(t *testing.T)
| 258 | } |
| 259 | |
| 260 | func TestContainerContextWrite(t *testing.T) { |
| 261 | unixTime := time.Now().AddDate(0, 0, -1).Unix() |
| 262 | expectedTime := time.Unix(unixTime, 0).String() |
| 263 | |
| 264 | cases := []struct { |
| 265 | context Context |
| 266 | expected string |
| 267 | }{ |
| 268 | // Errors |
| 269 | { |
| 270 | context: Context{Format: "{{InvalidFunction}}"}, |
| 271 | expected: `template parsing error: template: :1: function "InvalidFunction" not defined`, |
| 272 | }, |
| 273 | { |
| 274 | context: Context{Format: "{{nil}}"}, |
| 275 | expected: `template parsing error: template: :1:2: executing "" at <nil>: nil is not a command`, |
| 276 | }, |
| 277 | // Table Format |
| 278 | { |
| 279 | context: Context{Format: NewContainerFormat("table", false, true)}, |
| 280 | expected: `CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES SIZE |
| 281 | containerID1 ubuntu "" 24 hours ago foobar_baz 0B |
| 282 | containerID2 ubuntu "" 24 hours ago foobar_bar 0B |
| 283 | `, |
| 284 | }, |
| 285 | { |
| 286 | context: Context{Format: NewContainerFormat("table", false, false)}, |
| 287 | expected: `CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES |
| 288 | containerID1 ubuntu "" 24 hours ago foobar_baz |
| 289 | containerID2 ubuntu "" 24 hours ago foobar_bar |
| 290 | `, |
| 291 | }, |
| 292 | { |
| 293 | context: Context{Format: NewContainerFormat("table {{.Image}}", false, false)}, |
| 294 | expected: "IMAGE\nubuntu\nubuntu\n", |
| 295 | }, |
| 296 | { |
| 297 | context: Context{Format: NewContainerFormat("table {{.Image}}", false, true)}, |
| 298 | expected: "IMAGE\nubuntu\nubuntu\n", |
| 299 | }, |
| 300 | { |
| 301 | context: Context{Format: NewContainerFormat("table {{.Image}}", true, false)}, |
| 302 | expected: "containerID1\ncontainerID2\n", |
| 303 | }, |
| 304 | { |
| 305 | context: Context{Format: NewContainerFormat("table", true, false)}, |
| 306 | expected: "containerID1\ncontainerID2\n", |
| 307 | }, |
| 308 | { |
| 309 | context: Context{Format: NewContainerFormat("table {{.State}}", false, true)}, |
| 310 | expected: "STATE\nrunning\nrunning\n", |
| 311 | }, |
| 312 | // Raw Format |
| 313 | { |
| 314 | context: Context{Format: NewContainerFormat("raw", false, false)}, |
| 315 | expected: fmt.Sprintf(`container_id: containerID1 |
| 316 | image: ubuntu |
| 317 | command: "" |
nothing calls this directly
no test coverage detected
searching dependent graphs…