Skip to content

Commit

Permalink
Add test for folder rename - Windows
Browse files Browse the repository at this point in the history
Summary:
# Context

We are introducing EdenFS notifications to support scalable and ergonomic file system notifications for EdenFS mounts.

# This Diff
This diff adds tests for folder renaming on windows. This is allowed for uncommited folders but not for commited ones

# Technical Details
Update setup to create a folder and a subfile
Add tests for:
rename folder
rename folder with file
rename folder with file- commited

# Discussion Points
Currently there is no file removed notification for the file in the old folder. Should there be?

Reviewed By: MichaelCuevas

Differential Revision: D66994320

fbshipit-source-id: 3915fe17bcb6259d1f7539ad89ad7696fad53879
  • Loading branch information
Chris Dinh authored and facebook-github-bot committed Dec 12, 2024
1 parent c7f59f2 commit 37b12da
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
60 changes: 60 additions & 0 deletions eden/integration/changes_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,3 +298,63 @@ def test_replace_file(self):
self.repo_write_file("gone_file", "replaced_contents", add=False)
with self.assertRaises(FileExistsError):
self.rename("test_file", "gone_file")

# Renaming uncommitted folders in windows is an add and delete
def test_rename_folder(self):
self.mkdir("test_folder")
position = self.client.getCurrentJournalPosition(self.mount_path_bytes)
self.rename("test_folder", "best_folder")
changes = self.getChangesSinceV2(position=position)
expected_changes = [
buildSmallChange(
SmallChangeNotification.REMOVED, Dtype.DIR, path=b"test_folder"
),
buildSmallChange(
SmallChangeNotification.ADDED, Dtype.DIR, path=b"best_folder"
),
]
self.assertTrue(self.check_changes(changes.changes, expected_changes))

# Renaming uncomitted folders with a file
def test_rename_folder_uncommitted_file(self):
self.mkdir("test_folder")
self.repo_write_file("test_folder/test_file", "contents", add=True)
position = self.client.getCurrentJournalPosition(self.mount_path_bytes)
self.rename("test_folder", "best_folder")
position2 = self.client.getCurrentJournalPosition(self.mount_path_bytes)
# ensure that the file change is synced to the new folder
self.syncProjFS(position2)
changes = self.getChangesSinceV2(position=position)
expected_changes = [
buildSmallChange(
SmallChangeNotification.REMOVED, Dtype.DIR, path=b"test_folder"
),
buildSmallChange(
SmallChangeNotification.ADDED, Dtype.DIR, path=b"best_folder"
),
# No REMOVED for test_file, on ProjFS, there's no change reported
# for subfolders and files if the parent folder gets moved
buildSmallChange(
SmallChangeNotification.ADDED,
Dtype.REGULAR,
path=b"best_folder/test_file",
),
]
self.assertTrue(self.check_changes(changes.changes, expected_changes))

# Renaming folders that have been checked out is not allowed
def test_rename_folder_committed_file(self):
# Files created in setup.
with self.assertRaises(OSError):
self.rename(self.get_path("the_land"), self.get_path("deepest_blue"))

# In windows, files that were checked out via checkout cannot be renamed
self.mkdir("test_folder")
self.repo_write_file("test_folder/test_file", "contents", add=True)
self.eden_repo.hg()
commit1 = self.eden_repo.commit("commit 1")
self.eden_repo.hg("goto", self.commit0)
self.eden_repo.hg("goto", commit1)

with self.assertRaises(OSError):
self.rename(self.get_path("test_folder"), self.get_path("best_folder"))
1 change: 1 addition & 0 deletions eden/integration/lib/journal_test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class JournalTestBase(testcase.EdenRepoTest):
def populate_repo(self) -> None:
# Create the initial repo. It requires at least 1 file and 1 commit
self.repo.write_file("hello", "bonjour\n")
self.repo.write_file("the_land/is", "cloaked\n")
self.commit0 = self.repo.commit("Commit 0.")

def setUp(self) -> None:
Expand Down

0 comments on commit 37b12da

Please sign in to comment.