expectPortProblem function

Problem expectPortProblem(
  1. Problem problem, {
  2. required PortName port,
  3. required PortErrorCode code,
  4. String? operation,
})

Requires problem to be the envelope this library mints for port/code.

Consumers assert seam failures constantly; without this they would re-derive the type URI, status, recoverable flag, and data shape in every test.

Implementation

Problem expectPortProblem(
  Problem problem, {
  required PortName port,
  required PortErrorCode code,
  String? operation,
}) {
  final Object? actualPort = problem.data['port'];
  final Object? actualCode = problem.data['code'];
  if (actualPort != port.name || actualCode != code.wireId) {
    throw SeamAssertionFailure(
      'Expected a ${port.name}/${code.wireId} problem, got '
      '$actualPort/$actualCode.',
    );
  }
  if (problem.status != code.status) {
    throw SeamAssertionFailure(
      'Expected status ${code.status} for ${code.wireId}, got '
      '${problem.status}.',
    );
  }
  if (problem.recoverable != code.recoverable) {
    throw SeamAssertionFailure(
      'Expected recoverable=${code.recoverable} for ${code.wireId}, got '
      '${problem.recoverable}.',
    );
  }
  if (operation != null && problem.data['operation'] != operation) {
    throw SeamAssertionFailure(
      'Expected operation "$operation", got "${problem.data['operation']}".',
    );
  }
  return problem;
}