| 417 | } |
| 418 | |
| 419 | func TestRename(t *testing.T) { |
| 420 | condSkip(t) |
| 421 | inEmptyMutDir(t, func(env *mountEnv, rootDir string) { |
| 422 | name1 := filepath.Join(rootDir, "1") |
| 423 | name2 := filepath.Join(rootDir, "2") |
| 424 | subdir := filepath.Join(rootDir, "dir") |
| 425 | name3 := filepath.Join(subdir, "3") |
| 426 | |
| 427 | contents := []byte("Some file contents") |
| 428 | const gone = "ENOENT" |
| 429 | const reg = "file -rw-------, size 18" |
| 430 | |
| 431 | if err := os.WriteFile(name1, contents, 0644); err != nil { |
| 432 | t.Fatal(err) |
| 433 | } |
| 434 | if err := os.Mkdir(subdir, 0755); err != nil { |
| 435 | t.Fatal(err) |
| 436 | } |
| 437 | |
| 438 | if got, want := statStr(name1), reg; got != want { |
| 439 | t.Errorf("name1 = %q; want %q", got, want) |
| 440 | } |
| 441 | if err := os.Rename(name1, name2); err != nil { |
| 442 | t.Fatal(err) |
| 443 | } |
| 444 | if got, want := statStr(name1), gone; got != want { |
| 445 | t.Errorf("name1 = %q; want %q", got, want) |
| 446 | } |
| 447 | if got, want := statStr(name2), reg; got != want { |
| 448 | t.Errorf("name2 = %q; want %q", got, want) |
| 449 | } |
| 450 | |
| 451 | // Moving to a different directory. |
| 452 | if err := os.Rename(name2, name3); err != nil { |
| 453 | t.Fatal(err) |
| 454 | } |
| 455 | if got, want := statStr(name2), gone; got != want { |
| 456 | t.Errorf("name2 = %q; want %q", got, want) |
| 457 | } |
| 458 | if got, want := statStr(name3), reg; got != want { |
| 459 | t.Errorf("name3 = %q; want %q", got, want) |
| 460 | } |
| 461 | }) |
| 462 | } |
| 463 | |
| 464 | func TestMoveAt(t *testing.T) { |
| 465 | condSkip(t) |