Signed-off-by: Brian Goff <cpuguy83@gmail.com>
| ... | ... |
@@ -62,6 +62,12 @@ func newListCommand(dockerCli *command.DockerCli) *cobra.Command {
|
| 62 | 62 |
type preProcessor struct {
|
| 63 | 63 |
types.Container |
| 64 | 64 |
opts *types.ContainerListOptions |
| 65 |
+ |
|
| 66 |
+ // Fields that need to exist so the template doesn't error out |
|
| 67 |
+ // These are needed since they are available on the final object but are not |
|
| 68 |
+ // fields in types.Container |
|
| 69 |
+ // TODO(cpuguy83): this seems rather broken |
|
| 70 |
+ Networks, CreatedAt, RunningFor bool |
|
| 65 | 71 |
} |
| 66 | 72 |
|
| 67 | 73 |
// Size sets the size option when called by a template execution. |
| ... | ... |
@@ -70,13 +76,6 @@ func (p *preProcessor) Size() bool {
|
| 70 | 70 |
return true |
| 71 | 71 |
} |
| 72 | 72 |
|
| 73 |
-// Networks does nothing but return true. |
|
| 74 |
-// It is needed to avoid the template check to fail as this field |
|
| 75 |
-// doesn't exist in `types.Container` |
|
| 76 |
-func (p *preProcessor) Networks() bool {
|
|
| 77 |
- return true |
|
| 78 |
-} |
|
| 79 |
- |
|
| 80 | 73 |
func buildContainerListOptions(opts *psOptions) (*types.ContainerListOptions, error) {
|
| 81 | 74 |
options := &types.ContainerListOptions{
|
| 82 | 75 |
All: opts.all, |
| ... | ... |
@@ -370,3 +370,29 @@ func TestContainerContextWriteJSONField(t *testing.T) {
|
| 370 | 370 |
assert.Equal(t, s, containers[i].ID) |
| 371 | 371 |
} |
| 372 | 372 |
} |
| 373 |
+ |
|
| 374 |
+func TestContainerBackCompat(t *testing.T) {
|
|
| 375 |
+ containers := []types.Container{types.Container{ID: "brewhaha"}}
|
|
| 376 |
+ cases := []string{
|
|
| 377 |
+ "ID", |
|
| 378 |
+ "Names", |
|
| 379 |
+ "Image", |
|
| 380 |
+ "Command", |
|
| 381 |
+ "CreatedAt", |
|
| 382 |
+ "RunningFor", |
|
| 383 |
+ "Ports", |
|
| 384 |
+ "Status", |
|
| 385 |
+ "Size", |
|
| 386 |
+ "Labels", |
|
| 387 |
+ "Mounts", |
|
| 388 |
+ } |
|
| 389 |
+ buf := bytes.NewBuffer(nil) |
|
| 390 |
+ for _, c := range cases {
|
|
| 391 |
+ ctx := Context{Format: Format(fmt.Sprintf("{{ .%s }}", c)), Output: buf}
|
|
| 392 |
+ if err := ContainerWrite(ctx, containers); err != nil {
|
|
| 393 |
+ t.Log("could not render template for field '%s': %v", c, err)
|
|
| 394 |
+ t.Fail() |
|
| 395 |
+ } |
|
| 396 |
+ buf.Reset() |
|
| 397 |
+ } |
|
| 398 |
+} |