test the file contents even on failure cases

This commit is contained in:
itchyny 2020-01-09 12:07:59 +09:00
parent a4647e9205
commit 42b640ffe3

View file

@ -142,6 +142,10 @@ func TestRename(t *testing.T) {
"foo": "0",
"bar": "1",
},
expected: map[string]string{
"foo": "0",
"bar": "1",
},
err: &emptyPathError{},
},
{
@ -154,6 +158,10 @@ func TestRename(t *testing.T) {
"foo": "0",
"bar": "1",
},
expected: map[string]string{
"foo": "0",
"bar": "1",
},
err: &emptyPathError{},
},
{
@ -168,6 +176,11 @@ func TestRename(t *testing.T) {
"bar": "1",
"baz": "2",
},
expected: map[string]string{
"foo": "0",
"bar": "1",
"baz": "2",
},
err: &sameDestinationError{"baz"},
},
{
@ -196,6 +209,10 @@ func TestRename(t *testing.T) {
"foo": "0",
"bar": "1",
},
expected: map[string]string{
"foo": "0",
"bar": "1",
},
err: &sameSourceError{"foo"},
},
{
@ -208,6 +225,10 @@ func TestRename(t *testing.T) {
"foo": "0",
"bar": "1",
},
expected: map[string]string{
"foo": "0",
"bar": "1",
},
err: &sameDestinationError{"baz"},
},
{
@ -262,13 +283,13 @@ func TestRename(t *testing.T) {
require.NoError(t, setupFiles(tc.contents))
rs, _ := buildRenames(clone(tc.files))
assert.Equal(t, tc.count, len(rs))
got := Rename(tc.files)
err = Rename(tc.files)
if tc.err == nil {
require.NoError(t, got)
assert.Equal(t, tc.expected, fileContents("."))
assert.NoError(t, err)
} else {
assert.Equal(t, tc.err, got)
assert.Equal(t, tc.err, err)
}
assert.Equal(t, tc.expected, fileContents("."))
})
}
}