mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
6052f2b396
I noticed that we're using a homegrown package for assertions. The functions are extremely similar to testify, but with enough slight differences to be confusing (for example, Equal takes its arguments in a different order). We already vendor testify, and it's used in a few places by tests. I also found some problems with pkg/testutil/assert. For example, the NotNil function seems to be broken. It checks the argument against "nil", which only works for an interface. If you pass in a nil map or slice, the equality check will fail. In the interest of avoiding NIH, I'm proposing replacing pkg/testutil/assert with testify. The test code looks almost the same, but we avoid the confusion of having two similar but slightly different assertion packages, and having to maintain our own package instead of using a commonly-used one. In the process, I found a few places where the tests should halt if an assertion fails, so I've made those cases (that I noticed) use "require" instead of "assert", and I've vendored the "require" package from testify alongside the already-present "assert" package. Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
59 lines
1.3 KiB
Go
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/stretchr/testify/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.EqualError(t, err, testcase.expected)
|
|
} else {
|
|
assert.Equal(t, testcase.expected, out.String())
|
|
}
|
|
}
|
|
}
|