acpd_test 1.0.0
acpd_test: ^1.0.0 copied to clipboard
Test utilities for acpd — in-memory transport pair, mock agent/client, and protocol fixtures.
acpd_test #
English · 简体中文
Deterministic test utilities for acpd.
Features #
MemoryTransportPair: two frame-aware transports wired back-to-back.MemoryLineTransportPair: newline-delimited JSON transport pair for codec tests.MockAgentandMockClient: programmable peers backed by realConnectioninstances.- Explicit close behavior suitable for unit and integration tests.
Usage #
import 'package:acpd/acpd.dart';
import 'package:acpd_test/acpd_test.dart';
final pair = MemoryTransportPair();
final client = ClientRole().connect(pair.left);
final agent = AgentRole()
.handle('echo', (params, context) => params)
.connect(pair.right);
try {
final result = await client.connection.sendRequest<Map<String, Object?>>(
'echo',
params: const <String, Object?>{'value': 'hello'},
mapResult: (value) => Map<String, Object?>.from(value! as Map),
);
print(result['value']);
} finally {
await client.close();
await agent.close();
await pair.close();
}
See the package example/ for a complete runnable exchange.
License #
Apache License 2.0. See LICENSE.