Skip to content

Commit

Permalink
Update contrib guide and script to reference integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kraenhansen committed Nov 12, 2024
1 parent 9a94d5c commit ccb1082
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 25 deletions.
39 changes: 25 additions & 14 deletions contrib/guide-testing-exclude-icloud-backup.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
# Guide: Testing Exclude iCloud Backup

## Prerequisites

- macOS
- iOS Simulator

## Testing

Ensure you have booted a simulator and execute the integration tests on iOS:

```sh
MOCHA_REMOTE_GREP='icloud' npm run test:ios --workspace @realm/react-native-test-app-tests
```

In the command above, we're explicitly grepping for the icloud backup tests.

To verify if a file has been successfully excluded from iCloud backup, you need to check the file's attributes.
We provide an easy script to do so:

```sh
./contrib/scripts/check-exclude-icloud-backup.sh
```

## Testing in your own app

Before starting the testing process, you need to configure your Realm database to either include or exclude files from iCloud backup. This is done by setting the `excludeFromIcloudBackup` property in your Realm configuration. Here is an example of how to set this property:

```javascript
Expand All @@ -16,20 +40,7 @@ const realm = new Realm(realmConfig);

Make sure to replace the schema and path with your actual Realm schema and desired file path. Once you have configured this property, you can proceed with the following steps to test if the exclusion from iCloud backup is working correctly.

## Prerequisites

- macOS
- iOS Simulator

## Testing

To verify if a file has been successfully excluded from iCloud backup, you need to check the file's attributes. We provide an easy script to do so. Ensure you have booted a simulator with an app using Realm. From the root of the project, run:

```sh
contrib/scripts/check-exclude-icloud-backup.sh <com.your.app.bundle>
```

If the script doesn't work, you can also check it manually. First, get the path of the Realm files from the simulator's Documents folder by running:
First, get the path of the Realm files from the simulator's Documents folder by running:

```sh
open `xcrun simctl get_app_container booted com.your.app.bundleId data`/Documents
Expand Down
16 changes: 5 additions & 11 deletions contrib/scripts/check-exclude-icloud-backup.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
#!/bin/bash

# Check if appbundle parameter is provided
if [ -z "$1" ]; then
echo "Usage: $0 <com.app.bundle.id>"
exit 1
fi

appbundle=$1
TEST_APP_BUNDLE_ID=com.microsoft.ReactTestApp

# Check if a simulator is booted
booted_simulators=$(xcrun simctl list | grep "Booted")
Expand All @@ -25,15 +19,15 @@ if [ "$booted_count" -gt 1 ]; then
fi

# Extract the name of the booted simulator
booted_simulator=$(echo "$booted_simulator" | xargs)
booted_simulator=$(echo "$booted_simulators" | xargs)
echo -e "Running script on simulator: $booted_simulator\n"

# Get the app container path
app_container_path=$(xcrun simctl get_app_container booted "$appbundle" data 2>/dev/null)
app_container_path=$(xcrun simctl get_app_container booted "$TEST_APP_BUNDLE_ID" data 2>/dev/null)

# Check if the command was successful
if [ $? -ne 0 ] || [ -z "$app_container_path" ]; then
echo "Failed to get app container path for $appbundle"
echo "Failed to get app container path for $TEST_APP_BUNDLE_ID"
exit 1
fi

Expand All @@ -47,7 +41,7 @@ if [ ! -d "$documents_path" ]; then
fi

# Run xattr on all files in the directory
for file in "$documents_path"/*; do
for file in "$documents_path"/icloud-backup-tests/*.realm; do
if [ -e "$file" ]; then
filename=$(basename "$file")
attrs=$(xattr "$file" 2>/dev/null)
Expand Down

0 comments on commit ccb1082

Please sign in to comment.