mirror of
https://gitlab.com/veilid/veilid.git
synced 2025-08-18 03:10:58 -04:00
update ndk and gradle versions
add subpackage to veilid-flutter with test fixtures for writing veilid integration tests in dart
This commit is contained in:
parent
bcacaeb300
commit
bcee358a0e
20 changed files with 305 additions and 80 deletions
|
@ -1,9 +1,15 @@
|
|||
include: package:flutter_lints/flutter.yaml
|
||||
|
||||
include: package:lint_hard/all.yaml
|
||||
analyzer:
|
||||
errors:
|
||||
invalid_annotation_target: ignore
|
||||
|
||||
exclude:
|
||||
- '**/*.g.dart'
|
||||
- '**/*.freezed.dart'
|
||||
- '**/*.pb.dart'
|
||||
- '**/*.pbenum.dart'
|
||||
- '**/*.pbjson.dart'
|
||||
- '**/*.pbserver.dart'
|
||||
linter:
|
||||
rules:
|
||||
- unawaited_futures
|
||||
unawaited_futures: true
|
||||
avoid_positional_boolean_parameters: false
|
||||
|
|
|
@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
|
|||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.3-all.zip
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
@Timeout(Duration(seconds: 60))
|
||||
|
||||
library veilid_flutter_integration_test;
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:integration_test/integration_test.dart';
|
||||
import 'package:veilid_test/veilid_test.dart';
|
||||
|
||||
import 'fixtures.dart';
|
||||
import 'test_crypto.dart';
|
||||
import 'test_routing_context.dart';
|
||||
import 'test_table_db.dart';
|
||||
|
@ -12,7 +14,8 @@ import 'test_dht.dart';
|
|||
|
||||
void main() {
|
||||
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
|
||||
final fixture = DefaultFixture();
|
||||
final fixture =
|
||||
DefaultVeilidFixture(programName: 'veilid_flutter integration test');
|
||||
|
||||
group('Unstarted Tests', () {
|
||||
test('veilid config defaults', testVeilidConfigDefaults);
|
||||
|
|
|
@ -1,152 +0,0 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:mutex/mutex.dart';
|
||||
import 'package:veilid/veilid.dart';
|
||||
|
||||
class DefaultFixture {
|
||||
DefaultFixture();
|
||||
|
||||
StreamSubscription<VeilidUpdate>? _veilidUpdateSubscription;
|
||||
Stream<VeilidUpdate>? _veilidUpdateStream;
|
||||
final StreamController<VeilidUpdate> _updateStreamController =
|
||||
StreamController.broadcast();
|
||||
|
||||
static final _fixtureMutex = Mutex();
|
||||
|
||||
Future<void> setUp() async {
|
||||
await _fixtureMutex.acquire();
|
||||
|
||||
assert(_veilidUpdateStream == null, 'should not set up fixture twice');
|
||||
|
||||
final ignoreLogTargetsStr =
|
||||
// ignore: do_not_use_environment
|
||||
const String.fromEnvironment('IGNORE_LOG_TARGETS').trim();
|
||||
final ignoreLogTargets = ignoreLogTargetsStr.isEmpty
|
||||
? <String>[]
|
||||
: ignoreLogTargetsStr.split(',').map((e) => e.trim()).toList();
|
||||
|
||||
final Map<String, dynamic> platformConfigJson;
|
||||
if (kIsWeb) {
|
||||
final platformConfig = VeilidWASMConfig(
|
||||
logging: VeilidWASMConfigLogging(
|
||||
performance: VeilidWASMConfigLoggingPerformance(
|
||||
enabled: true,
|
||||
level: VeilidConfigLogLevel.debug,
|
||||
logsInTimings: true,
|
||||
logsInConsole: false,
|
||||
ignoreLogTargets: ignoreLogTargets,
|
||||
),
|
||||
api: VeilidWASMConfigLoggingApi(
|
||||
enabled: true,
|
||||
level: VeilidConfigLogLevel.info,
|
||||
ignoreLogTargets: ignoreLogTargets,
|
||||
)));
|
||||
platformConfigJson = platformConfig.toJson();
|
||||
} else {
|
||||
final platformConfig = VeilidFFIConfig(
|
||||
logging: VeilidFFIConfigLogging(
|
||||
terminal: VeilidFFIConfigLoggingTerminal(
|
||||
enabled: false,
|
||||
level: VeilidConfigLogLevel.debug,
|
||||
ignoreLogTargets: ignoreLogTargets,
|
||||
),
|
||||
otlp: VeilidFFIConfigLoggingOtlp(
|
||||
enabled: false,
|
||||
level: VeilidConfigLogLevel.trace,
|
||||
grpcEndpoint: 'localhost:4317',
|
||||
serviceName: 'Veilid Tests',
|
||||
ignoreLogTargets: ignoreLogTargets,
|
||||
),
|
||||
api: VeilidFFIConfigLoggingApi(
|
||||
enabled: true,
|
||||
// level: VeilidConfigLogLevel.debug,
|
||||
level: VeilidConfigLogLevel.info,
|
||||
ignoreLogTargets: ignoreLogTargets,
|
||||
)));
|
||||
platformConfigJson = platformConfig.toJson();
|
||||
}
|
||||
Veilid.instance.initializeVeilidCore(platformConfigJson);
|
||||
|
||||
var config = await getDefaultVeilidConfig(
|
||||
isWeb: kIsWeb,
|
||||
programName: 'Veilid Tests',
|
||||
// ignore: avoid_redundant_argument_values, do_not_use_environment
|
||||
bootstrap: const String.fromEnvironment('BOOTSTRAP'),
|
||||
// ignore: avoid_redundant_argument_values, do_not_use_environment
|
||||
networkKeyPassword: const String.fromEnvironment('NETWORK_KEY'),
|
||||
);
|
||||
|
||||
config =
|
||||
config.copyWith(tableStore: config.tableStore.copyWith(delete: true));
|
||||
config = config.copyWith(
|
||||
protectedStore: config.protectedStore.copyWith(delete: true));
|
||||
config =
|
||||
config.copyWith(blockStore: config.blockStore.copyWith(delete: true));
|
||||
|
||||
final us =
|
||||
_veilidUpdateStream = await Veilid.instance.startupVeilidCore(config);
|
||||
|
||||
_veilidUpdateSubscription = us.listen((update) {
|
||||
if (update is VeilidLog) {
|
||||
// print(update.message);
|
||||
} else if (update is VeilidUpdateAttachment) {
|
||||
} else if (update is VeilidUpdateConfig) {
|
||||
} else if (update is VeilidUpdateNetwork) {
|
||||
} else if (update is VeilidAppMessage) {
|
||||
} else if (update is VeilidAppCall) {
|
||||
} else if (update is VeilidUpdateValueChange) {
|
||||
} else if (update is VeilidUpdateRouteChange) {
|
||||
} else {
|
||||
throw Exception('unexpected update: $update');
|
||||
}
|
||||
_updateStreamController.sink.add(update);
|
||||
});
|
||||
}
|
||||
|
||||
Stream<VeilidUpdate> get updateStream => _updateStreamController.stream;
|
||||
|
||||
Future<void> attach() async {
|
||||
await Veilid.instance.attach();
|
||||
|
||||
// Wait for attached state
|
||||
while (true) {
|
||||
final state = await Veilid.instance.getVeilidState();
|
||||
var done = false;
|
||||
if (state.attachment.publicInternetReady) {
|
||||
switch (state.attachment.state) {
|
||||
case AttachmentState.detached:
|
||||
break;
|
||||
case AttachmentState.attaching:
|
||||
break;
|
||||
case AttachmentState.detaching:
|
||||
break;
|
||||
default:
|
||||
done = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (done) {
|
||||
break;
|
||||
}
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> detach() async {
|
||||
await Veilid.instance.detach();
|
||||
}
|
||||
|
||||
Future<void> tearDown() async {
|
||||
assert(_veilidUpdateStream != null, 'should not tearDown without setUp');
|
||||
|
||||
final cancelFut = _veilidUpdateSubscription?.cancel();
|
||||
await Veilid.instance.shutdownVeilidCore();
|
||||
await cancelFut;
|
||||
|
||||
_veilidUpdateSubscription = null;
|
||||
_veilidUpdateStream = null;
|
||||
|
||||
_fixtureMutex.release();
|
||||
}
|
||||
}
|
|
@ -1,8 +1,8 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:veilid/veilid.dart';
|
||||
import 'package:loggy/loggy.dart';
|
||||
import 'package:ansicolor/ansicolor.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:loggy/loggy.dart';
|
||||
import 'package:veilid/veilid.dart';
|
||||
|
||||
// Loggy tools
|
||||
const LogLevel traceLevel = LogLevel('Trace', 1);
|
||||
|
@ -86,24 +86,23 @@ class CallbackPrinter extends LoggyPrinter {
|
|||
callback?.call(record);
|
||||
}
|
||||
|
||||
void setCallback(Function(LogRecord)? cb) {
|
||||
// ignore: use_setters_to_change_properties
|
||||
void setCallback(void Function(LogRecord)? cb) {
|
||||
callback = cb;
|
||||
}
|
||||
}
|
||||
|
||||
var globalTerminalPrinter = CallbackPrinter();
|
||||
CallbackPrinter globalTerminalPrinter = CallbackPrinter();
|
||||
|
||||
extension TraceLoggy on Loggy {
|
||||
void trace(dynamic message, [Object? error, StackTrace? stackTrace]) =>
|
||||
log(traceLevel, message, error, stackTrace);
|
||||
}
|
||||
|
||||
LogOptions getLogOptions(LogLevel? level) {
|
||||
return LogOptions(
|
||||
level ?? LogLevel.all,
|
||||
stackTraceLevel: LogLevel.error,
|
||||
);
|
||||
}
|
||||
LogOptions getLogOptions(LogLevel? level) => LogOptions(
|
||||
level ?? LogLevel.all,
|
||||
stackTraceLevel: LogLevel.error,
|
||||
);
|
||||
|
||||
void initLoggy() {
|
||||
Loggy.initLoggy(
|
||||
|
|
|
@ -6,7 +6,6 @@ import 'veilid_theme.dart';
|
|||
|
||||
const kDefaultTerminalStyle = TerminalStyle(
|
||||
fontSize: kDefaultMonoTerminalFontSize,
|
||||
height: kDefaultMonoTerminalFontHeight,
|
||||
fontFamily: kDefaultMonoTerminalFontFamily);
|
||||
|
||||
class LogTerminal extends StatefulWidget {
|
||||
|
@ -14,7 +13,7 @@ class LogTerminal extends StatefulWidget {
|
|||
|
||||
@override
|
||||
// ignore: library_private_types_in_public_api
|
||||
_LogTerminalState createState() => _LogTerminalState();
|
||||
State<LogTerminal> createState() => _LogTerminalState();
|
||||
}
|
||||
|
||||
class _LogTerminalState extends State<LogTerminal> {
|
||||
|
@ -28,32 +27,31 @@ class _LogTerminalState extends State<LogTerminal> {
|
|||
void initState() {
|
||||
super.initState();
|
||||
terminal.setLineFeedMode(true);
|
||||
globalTerminalPrinter
|
||||
.setCallback((log) => {terminal.write("${log.pretty()}\n")});
|
||||
globalTerminalPrinter.setCallback((log) {
|
||||
terminal.write('${log.pretty()}\n');
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return TerminalView(
|
||||
terminal,
|
||||
textStyle: kDefaultTerminalStyle,
|
||||
controller: terminalController,
|
||||
autofocus: true,
|
||||
backgroundOpacity: 0.9,
|
||||
onSecondaryTapDown: (details, offset) async {
|
||||
final selection = terminalController.selection;
|
||||
if (selection != null) {
|
||||
final text = terminal.buffer.getText(selection);
|
||||
terminalController.clearSelection();
|
||||
await Clipboard.setData(ClipboardData(text: text));
|
||||
} else {
|
||||
final data = await Clipboard.getData('text/plain');
|
||||
final text = data?.text;
|
||||
if (text != null) {
|
||||
terminal.paste(text);
|
||||
Widget build(BuildContext context) => TerminalView(
|
||||
terminal,
|
||||
textStyle: kDefaultTerminalStyle,
|
||||
controller: terminalController,
|
||||
autofocus: true,
|
||||
backgroundOpacity: 0.9,
|
||||
onSecondaryTapDown: (details, offset) async {
|
||||
final selection = terminalController.selection;
|
||||
if (selection != null) {
|
||||
final text = terminal.buffer.getText(selection);
|
||||
terminalController.clearSelection();
|
||||
await Clipboard.setData(ClipboardData(text: text));
|
||||
} else {
|
||||
final data = await Clipboard.getData('text/plain');
|
||||
final text = data?.text;
|
||||
if (text != null) {
|
||||
terminal.paste(text);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
|
|
@ -17,6 +17,14 @@ packages:
|
|||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.11.0"
|
||||
async_tools:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: async_tools
|
||||
sha256: "972f68ab663724d86260a31e363c1355ff493308441b872bf4e7b8adc67c832c"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.1.0"
|
||||
boolean_selector:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -139,14 +147,6 @@ packages:
|
|||
description: flutter
|
||||
source: sdk
|
||||
version: "0.0.0"
|
||||
flutter_lints:
|
||||
dependency: "direct dev"
|
||||
description:
|
||||
name: flutter_lints
|
||||
sha256: e2a421b7e59244faef694ba7b30562e489c2b489866e505074eb005cd7060db7
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.0.1"
|
||||
flutter_test:
|
||||
dependency: "direct dev"
|
||||
description: flutter
|
||||
|
@ -215,14 +215,14 @@ packages:
|
|||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.0.1"
|
||||
lints:
|
||||
dependency: transitive
|
||||
lint_hard:
|
||||
dependency: "direct dev"
|
||||
description:
|
||||
name: lints
|
||||
sha256: cbf8d4b858bb0134ef3ef87841abdf8d63bfc255c266b7bf6b39daa1085c4290
|
||||
name: lint_hard
|
||||
sha256: "44d15ec309b1a8e1aff99069df9dcb1597f49d5f588f32811ca28fb7b38c32fe"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.0.0"
|
||||
version: "4.0.0"
|
||||
loggy:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
|
@ -263,14 +263,6 @@ packages:
|
|||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.11.0"
|
||||
mutex:
|
||||
dependency: "direct dev"
|
||||
description:
|
||||
name: mutex
|
||||
sha256: "8827da25de792088eb33e572115a5eb0d61d61a3c01acbc8bcbe76ed78f1a1f2"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.1.0"
|
||||
path:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
|
@ -459,6 +451,13 @@ packages:
|
|||
relative: true
|
||||
source: path
|
||||
version: "0.3.1"
|
||||
veilid_test:
|
||||
dependency: "direct dev"
|
||||
description:
|
||||
path: "../packages/veilid_test"
|
||||
relative: true
|
||||
source: path
|
||||
version: "0.1.0"
|
||||
vm_service:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -508,5 +507,5 @@ packages:
|
|||
source: hosted
|
||||
version: "0.0.6"
|
||||
sdks:
|
||||
dart: ">=3.3.0 <4.0.0"
|
||||
dart: ">=3.3.4 <4.0.0"
|
||||
flutter: ">=3.19.1"
|
||||
|
|
|
@ -44,8 +44,10 @@ dev_dependencies:
|
|||
sdk: flutter
|
||||
integration_test:
|
||||
sdk: flutter
|
||||
flutter_lints: ^3.0.1
|
||||
mutex: ^3.1.0
|
||||
lint_hard: ^4.0.0
|
||||
veilid_test:
|
||||
path: ../packages/veilid_test
|
||||
|
||||
|
||||
# The following section is specific to Flutter.
|
||||
flutter:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue