mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
f9d2636787
Signed-off-by: Boaz Shuster <ripcurld.github@gmail.com>
55 lines
996 B
Go
55 lines
996 B
Go
package formatter
|
|
|
|
import (
|
|
"bytes"
|
|
"testing"
|
|
|
|
"github.com/docker/docker/api/types"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
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{
|
|
{"checkpoint-1"},
|
|
{"checkpoint-2"},
|
|
{"checkpoint-3"},
|
|
}
|
|
for _, testcase := range cases {
|
|
out := bytes.NewBufferString("")
|
|
testcase.context.Output = out
|
|
err := CheckpointWrite(testcase.context, checkpoints)
|
|
if err != nil {
|
|
assert.Error(t, err, testcase.expected)
|
|
} else {
|
|
assert.Equal(t, out.String(), testcase.expected)
|
|
}
|
|
}
|
|
}
|