2018-10-23 11:05:44 -04:00
|
|
|
package checkpoint
|
2017-03-13 17:19:46 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"testing"
|
|
|
|
|
2018-10-23 11:05:44 -04:00
|
|
|
"github.com/docker/cli/cli/command/formatter"
|
2017-03-13 17:19:46 -04:00
|
|
|
"github.com/docker/docker/api/types"
|
2020-02-22 12:12:14 -05:00
|
|
|
"gotest.tools/v3/assert"
|
2017-03-13 17:19:46 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestCheckpointContextFormatWrite(t *testing.T) {
|
|
|
|
cases := []struct {
|
2018-10-23 11:05:44 -04:00
|
|
|
context formatter.Context
|
2017-03-13 17:19:46 -04:00
|
|
|
expected string
|
|
|
|
}{
|
|
|
|
{
|
2018-10-23 11:05:44 -04:00
|
|
|
formatter.Context{Format: NewFormat(defaultCheckpointFormat)},
|
2017-03-13 17:19:46 -04:00
|
|
|
`CHECKPOINT NAME
|
|
|
|
checkpoint-1
|
|
|
|
checkpoint-2
|
|
|
|
checkpoint-3
|
|
|
|
`,
|
|
|
|
},
|
|
|
|
{
|
2018-10-23 11:05:44 -04:00
|
|
|
formatter.Context{Format: NewFormat("{{.Name}}")},
|
2017-03-13 17:19:46 -04:00
|
|
|
`checkpoint-1
|
|
|
|
checkpoint-2
|
|
|
|
checkpoint-3
|
|
|
|
`,
|
|
|
|
},
|
|
|
|
{
|
2018-10-23 11:05:44 -04:00
|
|
|
formatter.Context{Format: NewFormat("{{.Name}}:")},
|
2017-03-13 17:19:46 -04:00
|
|
|
`checkpoint-1:
|
|
|
|
checkpoint-2:
|
|
|
|
checkpoint-3:
|
|
|
|
`,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
checkpoints := []types.Checkpoint{
|
2018-04-10 09:55:00 -04:00
|
|
|
{Name: "checkpoint-1"},
|
|
|
|
{Name: "checkpoint-2"},
|
|
|
|
{Name: "checkpoint-3"},
|
2017-03-13 17:19:46 -04:00
|
|
|
}
|
|
|
|
for _, testcase := range cases {
|
|
|
|
out := bytes.NewBufferString("")
|
|
|
|
testcase.context.Output = out
|
2018-10-23 11:05:44 -04:00
|
|
|
err := FormatWrite(testcase.context, checkpoints)
|
2017-12-21 16:27:57 -05:00
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Equal(t, out.String(), testcase.expected)
|
2017-03-13 17:19:46 -04:00
|
|
|
}
|
|
|
|
}
|