CockpitTestStepResult constructor

CockpitTestStepResult({
  1. required String stepId,
  2. required String executionId,
  3. required String section,
  4. String? description,
  5. String? operation,
  6. int? timeoutMs,
  7. String? definitionPath,
  8. required CockpitTestStepStatus status,
  9. required DateTime startedAt,
  10. required int durationMs,
  11. CockpitTestStepOccurrence? occurrence,
  12. CockpitTestSourceLocation? sourceLocation,
  13. CockpitTestPlane? requestedPlane,
  14. CockpitTestPlane? actualPlane,
  15. String? driverId,
  16. CockpitLocatorResolution? locatorResolution,
  17. String? degradationReason,
  18. CockpitTestError? error,
  19. Iterable<String> evidence = const <String>[],
})

Creates a CockpitTestStepResult.

Implementation

CockpitTestStepResult({
  required this.stepId,
  required this.executionId,
  required this.section,
  this.description,
  this.operation,
  this.timeoutMs,
  this.definitionPath,
  required this.status,
  required this.startedAt,
  required this.durationMs,
  CockpitTestStepOccurrence? occurrence,
  this.sourceLocation,
  this.requestedPlane,
  this.actualPlane,
  this.driverId,
  this.locatorResolution,
  this.degradationReason,
  this.error,
  Iterable<String> evidence = const <String>[],
}) : occurrence = occurrence ?? CockpitTestStepOccurrence(),
     evidence = List<String>.unmodifiable(evidence) {
  CockpitTestValueReader.string(stepId, r'$.stepId', id: true);
  CockpitTestValueReader.string(executionId, r'$.executionId');
  if (description != null) {
    CockpitTestValueReader.string(description, r'$.description');
  }
  if (operation != null) {
    CockpitTestValueReader.string(operation, r'$.operation');
  }
  if (timeoutMs != null && timeoutMs! <= 0) {
    throw const FormatException('Step result timeoutMs must be positive.');
  }
  if (definitionPath != null) {
    CockpitTestValueReader.string(definitionPath, r'$.definitionPath');
  }
  if (!const <String>{'setup', 'main', 'finally'}.contains(section)) {
    throw const FormatException(
      'Step section must be setup, main, or finally.',
    );
  }
  if (durationMs < 0) {
    throw const FormatException('Step durationMs cannot be negative.');
  }
  if (driverId != null) {
    CockpitTestValueReader.string(driverId, r'$.driverId', id: true);
  }
  if (degradationReason != null) {
    CockpitTestValueReader.string(
      degradationReason,
      r'$.degradationReason',
      maximum: 512,
    );
  }
  final requiresError = switch (status) {
    CockpitTestStepStatus.failed ||
    CockpitTestStepStatus.blocked ||
    CockpitTestStepStatus.cancelled => true,
    CockpitTestStepStatus.pending ||
    CockpitTestStepStatus.running ||
    CockpitTestStepStatus.passed ||
    CockpitTestStepStatus.skipped => false,
  };
  if (requiresError != (error != null)) {
    throw const FormatException(
      'Step status and error presence are inconsistent.',
    );
  }
  for (var index = 0; index < this.evidence.length; index += 1) {
    CockpitTestValueReader.string(
      this.evidence[index],
      '\$.evidence[$index]',
      id: true,
    );
  }
}