(t *testing.T)
| 181 | } |
| 182 | |
| 183 | func TestCompareDifferentDirectories(t *testing.T) { |
| 184 | var buf bytes.Buffer |
| 185 | |
| 186 | ctx := context.Background() |
| 187 | |
| 188 | dirModTime := time.Date(2023, time.April, 12, 10, 30, 0, 0, time.UTC) |
| 189 | fileModTime := time.Date(2023, time.April, 12, 10, 30, 0, 0, time.UTC) |
| 190 | dirOwnerInfo := fs.OwnerInfo{UserID: 1000, GroupID: 1000} |
| 191 | dirMode := os.FileMode(0o777) |
| 192 | |
| 193 | oid1 := oidForString(t, "k", "sdkjfn") |
| 194 | oid2 := oidForString(t, "k", "dfjlgn") |
| 195 | |
| 196 | dir1 := createTestDirectory( |
| 197 | "testDir1", |
| 198 | dirModTime, |
| 199 | dirOwnerInfo, |
| 200 | dirMode, |
| 201 | oid1, |
| 202 | &testFile{testBaseEntry: testBaseEntry{modtime: fileModTime, name: "file1.txt"}, content: "abcdefghij"}, |
| 203 | &testFile{testBaseEntry: testBaseEntry{modtime: fileModTime, name: "file2.txt"}, content: "klmnopqrstuvwxyz"}, |
| 204 | ) |
| 205 | dir2 := createTestDirectory( |
| 206 | "testDir2", |
| 207 | dirModTime, |
| 208 | dirOwnerInfo, |
| 209 | dirMode, |
| 210 | oid2, |
| 211 | &testFile{testBaseEntry: testBaseEntry{modtime: fileModTime, name: "file3.txt"}, content: "abcdefghij1"}, |
| 212 | &testFile{testBaseEntry: testBaseEntry{modtime: fileModTime, name: "file4.txt"}, content: "klmnopqrstuvwxyz2"}, |
| 213 | ) |
| 214 | |
| 215 | c, err := diff.NewComparer(&buf, statsOnly) |
| 216 | require.NoError(t, err) |
| 217 | |
| 218 | t.Cleanup(func() { |
| 219 | _ = c.Close() |
| 220 | }) |
| 221 | |
| 222 | expectedStats := diff.Stats{} |
| 223 | expectedStats.FileEntries.Added = 2 |
| 224 | expectedStats.FileEntries.Removed = 2 |
| 225 | |
| 226 | expectedOutput := "added file ./file3.txt (11 bytes)\nadded file ./file4.txt (17 bytes)\n" + |
| 227 | "removed file ./file1.txt (10 bytes)\n" + |
| 228 | "removed file ./file2.txt (16 bytes)\n" |
| 229 | |
| 230 | actualStats, err := c.Compare(ctx, dir1, dir2) |
| 231 | |
| 232 | require.NoError(t, err) |
| 233 | require.Equal(t, expectedStats, actualStats) |
| 234 | require.Equal(t, expectedOutput, buf.String()) |
| 235 | } |
| 236 | |
| 237 | func TestCompareDifferentDirectories_DirTimeDiff(t *testing.T) { |
| 238 | var buf bytes.Buffer |
nothing calls this directly
no test coverage detected