Skip to content

Commit

Permalink
Add test for renamed folder - NIX
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

# Technical Details
New files:
Update thrift_objects.py to have a LargeChange generator

# Discussion Points

Reviewed By: lXXXw

Differential Revision: D66989434

fbshipit-source-id: a75d90d654fd63b88d3ea8d3ee631ea3bfd9f7f0
  • Loading branch information
Chris Dinh authored and facebook-github-bot committed Dec 12, 2024
1 parent d41391d commit c7f59f2
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
23 changes: 21 additions & 2 deletions eden/integration/changes_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@

import sys

from facebook.eden.ttypes import Dtype, LostChangesReason, SmallChangeNotification
from facebook.eden.ttypes import (
Dtype,
LargeChangeNotification,
LostChangesReason,
SmallChangeNotification,
)

from .lib import testcase
from .lib.journal_test_base import JournalTestBase, WindowsJournalTestBase
from .lib.thrift_objects import buildSmallChange, getLargeChangeSafe
from .lib.thrift_objects import buildLargeChange, buildSmallChange, getLargeChangeSafe


if sys.platform == "win32":
Expand Down Expand Up @@ -234,6 +239,20 @@ def test_modify_folder_chown(self):
]
self.assertTrue(self.check_changes(changes.changes, expected_changes))

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 = [
buildLargeChange(
LargeChangeNotification.DIRECTORYRENAMED,
from_bytes=b"test_folder",
to_bytes=b"best_folder",
),
]
self.assertTrue(self.check_changes(changes.changes, expected_changes))


@testcase.eden_repo_test
class ChangesTestWin(WindowsJournalTestBase):
Expand Down
35 changes: 35 additions & 0 deletions eden/integration/lib/thrift_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@
from facebook.eden.ttypes import (
Added,
ChangeNotification,
CommitTransition,
DirectoryRenamed,
Dtype,
LargeChangeNotification,
LostChanges,
LostChangesReason,
Modified,
Removed,
Renamed,
Expand Down Expand Up @@ -85,3 +89,34 @@ def buildSmallChange(
SmallChangeNotification(removed=Removed(fileType=fileType, path=path))
)
return ChangeNotification()


def buildLargeChange(
changeType: int,
from_bytes: Optional[bytes] = None,
to_bytes: Optional[bytes] = None,
lost_change_reason: Optional[LostChangesReason] = None,
) -> ChangeNotification:
if changeType == LargeChangeNotification.DIRECTORYRENAMED:
return ChangeNotification(
largeChange=LargeChangeNotification(
directoryRenamed=DirectoryRenamed(
from_PY_RESERVED_KEYWORD=from_bytes, to=to_bytes
)
)
)
elif changeType == LargeChangeNotification.COMMITTRANSITION:
return ChangeNotification(
largeChange=LargeChangeNotification(
commitTransition=CommitTransition(
from_PY_RESERVED_KEYWORD=from_bytes, to=to_bytes
)
)
)
elif changeType == LargeChangeNotification.LOSTCHANGES:
return ChangeNotification(
largeChange=LargeChangeNotification(
lostChanges=LostChanges(reason=lost_change_reason)
)
)
return ChangeNotification()

0 comments on commit c7f59f2

Please sign in to comment.