Skip to content

Commit

Permalink
chore(datastore): enable cloud sync in integration tests
Browse files Browse the repository at this point in the history
- Add reusable util for testing cloud sync opeartion
- Make integration tests configurable with
  - `--device-id` or `-d` to specify running device ID
  - `--enable-cloud-sync` or `-ec` to enable cloud sync in tests
  • Loading branch information
HuiSF committed Mar 25, 2022
1 parent bb46993 commit 65f5b0f
Show file tree
Hide file tree
Showing 39 changed files with 2,169 additions and 1,330 deletions.
89 changes: 89 additions & 0 deletions build-support/integ_test_android.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#!/bin/bash

if [ ! -d android ]; then
echo "No Android project to test" >&2
exit
fi

DEFAULT_DEVICE_ID="sdk"
DEFAULT_ENABLE_CLOUD_SYNC="true"

while [ $# -gt 0 ]; do
case "$1" in
-d|--device-id)
deviceId="$2"
;;
-ec|--enable-cloud-sync)
case "$2" in
true|false)
enableCloudSync="$2"
;;
*)
echo "Invalid value for $1"
exit 1
esac
;;
*)
echo "Invalid arguments"
exit 1
esac
shift
shift
done

deviceId=${deviceId:-$DEFAULT_DEVICE_ID}
enableCloudSync=${enableCloudSync:-$DEFAULT_ENABLE_CLOUD_SYNC}

declare -a testsList
declare -a resultsList

TARGET=integration_test/main_test.dart
if [ ! -e $TARGET ]; then
echo "$TARGET file not found" >&2
exit
fi

testsList+=("$TARGET")
if flutter test \
--no-pub \
-d $deviceId \
$TARGET; then
resultsList+=(0)
else
resultsList+=(1)
fi

TEST_ENTRIES="integration_test/separate_integration_tests/*.dart"
for ENTRY in $TEST_ENTRIES; do
if [ ! -f "${ENTRY}" ]; then
continue
fi
testsList+=("$ENTRY")
if [ $enableCloudSync == "true" ]; then
echo "Run $ENTRY WITH API Sync"
else
echo "Run $ENTRY WITHOUT API Sync"
fi

if flutter test \
--no-pub \
--dart-define ENABLE_CLOUD_SYNC=$enableCloudSync \
-d $deviceId \
$ENTRY; then
resultsList+=(0)
else
resultsList+=(1)
fi
done

testFailure=0
for i in "${!testsList[@]}"; do
if [ "${resultsList[i]}" == 0 ]; then
echo "${testsList[i]}"
else
testFailure=1
echo "${testsList[i]}"
fi
done

exit $testFailure
82 changes: 78 additions & 4 deletions build-support/integ_test_ios.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,99 @@ if [ ! -d ios ]; then
exit
fi

DEFAULT_DEVICE_ID="iPhone"
DEFAULT_ENABLE_CLOUD_SYNC="true"

while [ $# -gt 0 ]; do
case "$1" in
-d|--device-id)
deviceId="$2"
;;
-ec|--enable-cloud-sync)
case "$2" in
true|false)
enableCloudSync="$2"
;;
*)
echo "Invalid value for $1"
exit 1
esac
;;
*)
echo "Invalid arguments"
exit 1
esac
shift
shift
done

deviceId=${deviceId:-$DEFAULT_DEVICE_ID}
enableCloudSync=${enableCloudSync:-$DEFAULT_ENABLE_CLOUD_SYNC}

declare -a testsList
declare -a resultsList

TARGET=integration_test/main_test.dart
if [ ! -e $TARGET ]; then
echo "$TARGET file not found" >&2
exit
fi



# Use xcodebuild if 'RunnerTests' scheme exists, else `flutter test`
if xcodebuild -workspace ios/Runner.xcworkspace -list -json | jq -e '.workspace.schemes | index("RunnerTests")' >/dev/null; then
# Build app for testing
flutter build ios --no-pub --config-only --simulator --target=$TARGET

xcodebuild \
-workspace ios/Runner.xcworkspace \
-scheme RunnerTests \
-destination "platform=iOS Simulator,name=iPhone 12 Pro Max" \
test
else
flutter test \
testsList+=("$TARGET")
if flutter test \
--no-pub \
-d iPhone \
$TARGET
-d $deviceId \
$TARGET; then
resultsList+=(0)
else
resultsList+=(1)
fi
fi

TEST_ENTRIES="integration_test/separate_integration_tests/*.dart"
for ENTRY in $TEST_ENTRIES; do
if [ ! -f "${ENTRY}" ]; then
continue
fi
testsList+=("$ENTRY")
if [ $enableCloudSync == "true" ]; then
echo "Run $ENTRY WITH API Sync"
else
echo "Run $ENTRY WITHOUT API Sync"
fi

if flutter test \
--no-pub \
--dart-define ENABLE_CLOUD_SYNC=$enableCloudSync \
-d $deviceId \
$ENTRY; then
resultsList+=(0)
else
resultsList+=(1)
fi
done

testFailure=0
for i in "${!testsList[@]}"; do
if [ "${resultsList[i]}" == 0 ]; then
echo "${testsList[i]}"
else
testFailure=1
echo "${testsList[i]}"
fi
done

exit $testFailure
4 changes: 2 additions & 2 deletions melos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ scripts:
- Requires running Android and iOS simulators.

test:integration:android:
run: melos exec -c 1 "flutter test --no-pub integration_test/main_test.dart -d sdk"
run: melos exec -c 1 -- "$MELOS_ROOT_PATH/build-support/integ_test_android.sh" $@
description:
Run integration tests for a single package on an Android emulator.
- Run with `--no-select` to run for all applicable packages.
Expand All @@ -239,7 +239,7 @@ scripts:
scope: "*example*"

test:integration:ios:
run: melos exec -c 1 -- "$MELOS_ROOT_PATH/build-support/integ_test_ios.sh"
run: melos exec -c 1 -- "$MELOS_ROOT_PATH/build-support/integ_test_ios.sh" $@
description: Run integration tests for a single package on an iOS simulator.
- Run with `--no-select` to run for all applicable packages.
- Requires launching an iOS simulator prior to execution.
Expand Down
21 changes: 21 additions & 0 deletions packages/amplify_datastore/example/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,24 @@ app.*.map.json

# Exceptions to above rules.
!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages

#amplify-do-not-edit-begin
amplify/\#current-cloud-backend
amplify/.config/local-*
amplify/logs
amplify/mock-data
amplify/backend/amplify-meta.json
amplify/backend/.temp
build/
dist/
node_modules/
aws-exports.js
awsconfiguration.json
amplifyconfiguration.json
amplifyconfiguration.dart
amplify-build-config.json
amplify-gradle-config.json
amplifytools.xcconfig
.secret-*
**.sample
#amplify-do-not-edit-end
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@
import 'package:integration_test/integration_test.dart';
import 'package:flutter_test/flutter_test.dart';

import 'save_test.dart' as save_tests;
import 'query_test/query_test.dart' as query_test;
import 'model_type_test.dart' as model_type_tests;
import 'relationship_type_test.dart' as relationship_type_tests;
import 'observe_test.dart' as observe_tests;
import 'observe_query_test.dart' as observe_query_tests;
import 'clear_test.dart' as clear_tests;
Expand All @@ -34,10 +32,8 @@ void main() async {
await configureDataStore();
});

save_tests.main();
query_test.main();
model_type_tests.main();
relationship_type_tests.main();
observe_tests.main();
observe_query_tests.main();
clear_tests.main();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
* permissions and limitations under the License.
*/

import 'package:amplify_datastore/amplify_datastore.dart';

import 'package:amplify_datastore_example/models/ModelProvider.dart';
import 'package:integration_test/integration_test.dart';
import 'package:flutter_test/flutter_test.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
* permissions and limitations under the License.
*/

import 'package:amplify_datastore/amplify_datastore.dart';
import 'package:amplify_datastore_example/models/ModelProvider.dart';
import 'package:integration_test/integration_test.dart';
import 'package:flutter_test/flutter_test.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
* permissions and limitations under the License.
*/

import 'package:amplify_datastore/amplify_datastore.dart';
import 'package:amplify_datastore_example/models/ModelProvider.dart';
import 'package:integration_test/integration_test.dart';
import 'package:flutter_test/flutter_test.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
* permissions and limitations under the License.
*/

import 'package:amplify_datastore/amplify_datastore.dart';
import 'package:amplify_datastore_example/models/ModelProvider.dart';
import 'package:integration_test/integration_test.dart';
import 'package:flutter_test/flutter_test.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
* permissions and limitations under the License.
*/

import 'package:amplify_datastore/amplify_datastore.dart';
import 'package:amplify_datastore_example/models/ModelProvider.dart';
import 'package:integration_test/integration_test.dart';
import 'package:flutter_test/flutter_test.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import 'dart:math';

import 'package:amplify_datastore/amplify_datastore.dart';
import 'package:amplify_datastore_example/models/ModelProvider.dart';
import 'package:integration_test/integration_test.dart';
import 'package:flutter_test/flutter_test.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
* permissions and limitations under the License.
*/

import 'package:amplify_datastore/amplify_datastore.dart';

import 'package:amplify_datastore_example/models/ModelProvider.dart';
import 'package:integration_test/integration_test.dart';
import 'package:flutter_test/flutter_test.dart';
Expand Down
Loading

0 comments on commit 65f5b0f

Please sign in to comment.