SuiteInfo.fromProto constructor

SuiteInfo.fromProto(
  1. SuiteInfoProto proto
)

Implementation

factory SuiteInfo.fromProto(SuiteInfoProto proto) {
  final entryMap = Map.fromEntries([
    ...proto.groups.map(
        (group) => MapEntry(group.id.toInt(), GroupInfo.fromProto(group))),
    ...proto.tests
        .map((test) => MapEntry(test.id.toInt(), TestInfo.fromProto(test))),
  ]);
  final entryIdOfName = Map.fromEntries(
      entryMap.entries.map((e) => MapEntry(e.value.name, e.key)));

  if (entryIdOfName.length != entryMap.length) {
    Log.d(
        _kTag,
        '#groups=${proto.groups.length} #tests=${proto.tests.length} '
        'entryIdOfName.keys.length=${entryIdOfName.keys.length} entryIdOfName.keys=${entryIdOfName.keys.toList()} '
        'groups.name=${proto.groups.map((e) => e.name).toList()} tests.name=${proto.tests.map((e) => e.name).toList()} ');
    throw Exception(
        'Sanity check failed: Suite tests should have no duplicate names');
  }

  return SuiteInfo._(
    rootGroupId: proto.groupId.toInt(),
    entryMap: entryMap,
    entryIdOfName: entryIdOfName,
  );
}