2017-03-13 17:19:46 -04:00
|
|
|
package formatter
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/docker/docker/api/types"
|
2018-06-08 12:24:26 -04:00
|
|
|
"gotest.tools/assert"
|
2017-03-13 17:19:46 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestCheckpointContextFormatWrite(t *testing.T) {
|
|
|
|
cases := []struct {
|
|
|
|
context Context
|
|
|
|
expected string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
Context{Format: NewCheckpointFormat(defaultCheckpointFormat)},
|
|
|
|
`CHECKPOINT NAME
|
|
|
|
checkpoint-1
|
|
|
|
checkpoint-2
|
|
|
|
checkpoint-3
|
|
|
|
`,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Context{Format: NewCheckpointFormat("{{.Name}}")},
|
|
|
|
`checkpoint-1
|
|
|
|
checkpoint-2
|
|
|
|
checkpoint-3
|
|
|
|
`,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Context{Format: NewCheckpointFormat("{{.Name}}:")},
|
|
|
|
`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
|
|
|
|
err := CheckpointWrite(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
|
|
|
}
|
|
|
|
}
|