MCPcopy
hub / github.com/perkeep/perkeep / TestMoveAt

Function TestMoveAt

pkg/fs/fs_test.go:464–517  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

462}
463
464func TestMoveAt(t *testing.T) {
465 condSkip(t)
466 var beforeTime, afterTime time.Time
467 oldName := filepath.FromSlash("1/1/1")
468 newDir := filepath.FromSlash("2/1")
469 newName := filepath.Join(newDir, "1")
470 inEmptyMutDir(t, func(env *mountEnv, rootDir string) {
471 name1 := filepath.Join(rootDir, oldName)
472 name2 := filepath.Join(rootDir, newName)
473
474 if err := os.MkdirAll(name1, 0755); err != nil {
475 t.Fatal(err)
476 }
477 if err := os.MkdirAll(filepath.Join(rootDir, newDir), 0755); err != nil {
478 t.Fatal(err)
479 }
480
481 time.Sleep(time.Second)
482 beforeTime = time.Now()
483 time.Sleep(time.Second)
484
485 if err := os.Rename(name1, name2); err != nil {
486 t.Fatal(err)
487 }
488 if _, err := os.Stat(name2); err != nil {
489 t.Fatal(err)
490 }
491
492 time.Sleep(time.Second)
493 afterTime = time.Now()
494 })
495 pkmountTest(t, func(env *mountEnv) {
496 atPrefix := filepath.Join(env.mountPoint, "at")
497 testname := t.Name()
498
499 beforeName := filepath.Join(beforeTime.Format(time.RFC3339), testname, oldName)
500 notYetExistName := filepath.Join(beforeTime.Format(time.RFC3339), testname, newName)
501 afterName := filepath.Join(afterTime.Format(time.RFC3339), testname, newName)
502 goneName := filepath.Join(afterTime.Format(time.RFC3339), testname, oldName)
503
504 if _, err := os.Stat(filepath.Join(atPrefix, beforeName)); err != nil {
505 t.Errorf("%v before; want found, got not found; err: %v", beforeName, err)
506 }
507 if _, err := os.Stat(filepath.Join(atPrefix, notYetExistName)); !os.IsNotExist(err) {
508 t.Errorf("%v before; want not found, got found; err: %v", notYetExistName, err)
509 }
510 if _, err := os.Stat(filepath.Join(atPrefix, afterName)); err != nil {
511 t.Errorf("%v after; want found, got not found; err: %v", afterName, err)
512 }
513 if _, err := os.Stat(filepath.Join(atPrefix, goneName)); !os.IsNotExist(err) {
514 t.Errorf("%v after; want not found, got found; err: %v", goneName, err)
515 }
516 })
517}
518
519func parseXattrList(from []byte) map[string]bool {
520 attrNames := bytes.Split(from, []byte{0})

Callers

nothing calls this directly

Calls 8

condSkipFunction · 0.85
inEmptyMutDirFunction · 0.85
pkmountTestFunction · 0.85
FatalMethod · 0.80
MkdirAllMethod · 0.65
RenameMethod · 0.65
StatMethod · 0.65
NameMethod · 0.65

Tested by

no test coverage detected