CheckListingWithRoot checks the fs to see if it has the expected contents with the given precision. If expectedDirs is non nil then we check those too. Note that no directories returned is also OK as some remotes don't return directories. dir is the directory used for the listing.
(t *testing.T, f fs.Fs, dir string, items []Item, expectedDirs []string, precision time.Duration)
| 262 | // |
| 263 | // dir is the directory used for the listing. |
| 264 | func CheckListingWithRoot(t *testing.T, f fs.Fs, dir string, items []Item, expectedDirs []string, precision time.Duration) { |
| 265 | if expectedDirs != nil && !f.Features().CanHaveEmptyDirectories { |
| 266 | expectedDirs = filterEmptyDirs(t, items, expectedDirs) |
| 267 | } |
| 268 | is := NewItems(items) |
| 269 | ctx := context.Background() |
| 270 | oldErrors := accounting.Stats(ctx).GetErrors() |
| 271 | var objs []fs.Object |
| 272 | var dirs []fs.Directory |
| 273 | var err error |
| 274 | retries := *ListRetries |
| 275 | sleep := time.Second / 2 |
| 276 | wantListing := makeListingFromItems(items) |
| 277 | gotListing := "<unset>" |
| 278 | listingOK := false |
| 279 | for i := 1; i <= retries; i++ { |
| 280 | objs, dirs, err = walk.GetAll(ctx, f, dir, true, -1) |
| 281 | if err != nil && err != fs.ErrorDirNotFound { |
| 282 | t.Fatalf("Error listing: %v", err) |
| 283 | } |
| 284 | gotListing = makeListingFromObjects(objs) |
| 285 | |
| 286 | listingOK = wantListing == gotListing |
| 287 | if listingOK && (expectedDirs == nil || len(dirs) == len(expectedDirs)) { |
| 288 | // Put an extra sleep in if we did any retries just to make sure it really |
| 289 | // is consistent |
| 290 | if i != 1 { |
| 291 | extraSleep := 5*time.Second + sleep |
| 292 | t.Logf("Sleeping for %v just to make sure", extraSleep) |
| 293 | time.Sleep(extraSleep) |
| 294 | } |
| 295 | break |
| 296 | } |
| 297 | sleep *= 2 |
| 298 | t.Logf("Sleeping for %v for list eventual consistency: %d/%d", sleep, i, retries) |
| 299 | time.Sleep(sleep) |
| 300 | if doDirCacheFlush := f.Features().DirCacheFlush; doDirCacheFlush != nil { |
| 301 | t.Logf("Flushing the directory cache") |
| 302 | doDirCacheFlush() |
| 303 | } |
| 304 | } |
| 305 | assert.True(t, listingOK, fmt.Sprintf("listing wrong, want\n %s got\n %s", wantListing, gotListing)) |
| 306 | for _, obj := range objs { |
| 307 | require.NotNil(t, obj) |
| 308 | is.Find(t, obj, precision) |
| 309 | } |
| 310 | is.Done(t) |
| 311 | // Don't notice an error when listing an empty directory |
| 312 | if len(items) == 0 && oldErrors == 0 && accounting.Stats(ctx).GetErrors() == 1 { |
| 313 | accounting.Stats(ctx).ResetErrors() |
| 314 | } |
| 315 | // Check the directories |
| 316 | if expectedDirs != nil { |
| 317 | expectedDirsCopy := make([]string, len(expectedDirs)) |
| 318 | for i, dir := range expectedDirs { |
| 319 | expectedDirsCopy[i] = Normalize(dir) |
| 320 | } |
| 321 | actualDirs := []string{} |
searching dependent graphs…