- make it possible to extract the formatter implementation from the "common" code, that way, the formatter package stays small - extract some formatter into their own packages This is essentially moving the "formatter" implementation of each type in their respective packages. The *main* reason to do that, is to be able to depend on `cli/command/formatter` without depending of the implementation detail of the formatter. As of now, depending on `cli/command/formatter` means we depend on `docker/docker/api/types`, `docker/licensing`, … — that should not be the case. `formatter` should hold the common code (or helpers) to easily create formatter, not all formatter implementations. Signed-off-by: Vincent Demeester <vincent@sbr.pm>
54 lines
1002 B
Go
54 lines
1002 B
Go
package checkpoint
|
|
|
|
import (
|
|
"bytes"
|
|
"testing"
|
|
|
|
"github.com/docker/cli/cli/command/formatter"
|
|
"github.com/docker/docker/api/types"
|
|
"gotest.tools/assert"
|
|
)
|
|
|
|
func TestCheckpointContextFormatWrite(t *testing.T) {
|
|
cases := []struct {
|
|
context formatter.Context
|
|
expected string
|
|
}{
|
|
{
|
|
formatter.Context{Format: NewFormat(defaultCheckpointFormat)},
|
|
`CHECKPOINT NAME
|
|
checkpoint-1
|
|
checkpoint-2
|
|
checkpoint-3
|
|
`,
|
|
},
|
|
{
|
|
formatter.Context{Format: NewFormat("{{.Name}}")},
|
|
`checkpoint-1
|
|
checkpoint-2
|
|
checkpoint-3
|
|
`,
|
|
},
|
|
{
|
|
formatter.Context{Format: NewFormat("{{.Name}}:")},
|
|
`checkpoint-1:
|
|
checkpoint-2:
|
|
checkpoint-3:
|
|
`,
|
|
},
|
|
}
|
|
|
|
checkpoints := []types.Checkpoint{
|
|
{Name: "checkpoint-1"},
|
|
{Name: "checkpoint-2"},
|
|
{Name: "checkpoint-3"},
|
|
}
|
|
for _, testcase := range cases {
|
|
out := bytes.NewBufferString("")
|
|
testcase.context.Output = out
|
|
err := FormatWrite(testcase.context, checkpoints)
|
|
assert.NilError(t, err)
|
|
assert.Equal(t, out.String(), testcase.expected)
|
|
}
|
|
}
|