1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/cli/command/formatter/diff_test.go
Boaz Shuster 3dad39b957 Use formatter in docker diff
Signed-off-by: Boaz Shuster <ripcurld.github@gmail.com>
2017-03-30 10:33:40 +03:00

59 lines
1.3 KiB
Go

package formatter
import (
"bytes"
"testing"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/pkg/archive"
"github.com/docker/docker/pkg/testutil/assert"
)
func TestDiffContextFormatWrite(t *testing.T) {
// Check default output format (verbose and non-verbose mode) for table headers
cases := []struct {
context Context
expected string
}{
{
Context{Format: NewDiffFormat("table")},
`CHANGE TYPE PATH
C /var/log/app.log
A /usr/app/app.js
D /usr/app/old_app.js
`,
},
{
Context{Format: NewDiffFormat("table {{.Path}}")},
`PATH
/var/log/app.log
/usr/app/app.js
/usr/app/old_app.js
`,
},
{
Context{Format: NewDiffFormat("{{.Type}}: {{.Path}}")},
`C: /var/log/app.log
A: /usr/app/app.js
D: /usr/app/old_app.js
`,
},
}
diffs := []container.ContainerChangeResponseItem{
{archive.ChangeModify, "/var/log/app.log"},
{archive.ChangeAdd, "/usr/app/app.js"},
{archive.ChangeDelete, "/usr/app/old_app.js"},
}
for _, testcase := range cases {
out := bytes.NewBufferString("")
testcase.context.Output = out
err := DiffWrite(testcase.context, diffs)
if err != nil {
assert.Error(t, err, testcase.expected)
} else {
assert.Equal(t, out.String(), testcase.expected)
}
}
}