|
1 | 1 | package sumdiff |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "github.com/stretchr/testify/assert" |
4 | 5 | "testing" |
5 | 6 | ) |
6 | 7 |
|
7 | | -func TestDiffFile(t *testing.T) { |
8 | | - ok, err := EqualFile("../../test_data/a.txt", "../../test_data/b.txt") |
9 | | - t.Logf("result: %v, error: %v", ok, err) |
| 8 | +func TestEqFile(t *testing.T) { |
| 9 | + for _, v := range []struct { |
| 10 | + expected bool |
| 11 | + path1 string |
| 12 | + path2 string |
| 13 | + }{ |
| 14 | + {true, "./test_data/a.txt", "./test_data/b.txt"}, |
| 15 | + {false, "./test_data/a.txt", "./test_data/c.txt"}, |
| 16 | + {false, "./test_data/a.txt", "./test_data/d.txt"}, |
| 17 | + {false, "./test_data/c.txt", "./test_data/d.txt"}, |
| 18 | + } { |
| 19 | + ok, _, err := CmpFile(v.path1, v.path2) |
| 20 | + assert.NoError(t, err) |
| 21 | + assert.Equal(t, v.expected, ok, "Error at %v|%v", v.path1, v.path2) |
| 22 | + } |
10 | 23 | } |
11 | 24 |
|
12 | | -func TestDiffDir(t *testing.T) { |
13 | | - ok, err := EqualDir("../../test_data/data4", "../../test_data/data3") |
14 | | - t.Logf("result: %v, error: %v", ok, err) |
| 25 | +func TestEqDir(t *testing.T) { |
| 26 | + for _, v := range []struct { |
| 27 | + expected bool |
| 28 | + path1 string |
| 29 | + path2 string |
| 30 | + }{ |
| 31 | + {true, "./test_data/data1", "./test_data/data2"}, |
| 32 | + {false, "./test_data/data1", "./test_data/data3"}, |
| 33 | + {false, "./test_data/data1", "./test_data/data4"}, |
| 34 | + } { |
| 35 | + ok, _, err := CmpDir(v.path1, v.path2) |
| 36 | + assert.NoError(t, err) |
| 37 | + assert.Equal(t, v.expected, ok, "Error at %v|%v", v.path1, v.path2) |
| 38 | + } |
| 39 | +} |
| 40 | + |
| 41 | +func TestEq(t *testing.T) { |
| 42 | + for _, v := range []struct { |
| 43 | + expected bool |
| 44 | + path1 string |
| 45 | + path2 string |
| 46 | + }{ |
| 47 | + {true, "./test_data/a.txt", "./test_data/b.txt"}, |
| 48 | + {false, "./test_data/a.txt", "./test_data/c.txt"}, |
| 49 | + {false, "./test_data/a.txt", "./test_data/d.txt"}, |
| 50 | + {false, "./test_data/c.txt", "./test_data/d.txt"}, |
| 51 | + {true, "./test_data/data1", "./test_data/data2"}, |
| 52 | + {false, "./test_data/data1", "./test_data/data3"}, |
| 53 | + {false, "./test_data/data1", "./test_data/data4"}, |
| 54 | + } { |
| 55 | + ok, _, err := Cmp(v.path1, v.path2) |
| 56 | + assert.NoError(t, err) |
| 57 | + assert.Equal(t, v.expected, ok, "Error at %v|%v", v.path1, v.path2) |
| 58 | + } |
15 | 59 | } |
0 commit comments