LCOV - code coverage report
Current view: top level - src - testainers_utils.dart (source / functions) Coverage Total Hit
Test: testainers Lines: 25.7 % 35 9
Test Date: 2026-05-24 17:06:20 Functions: - 0 0

            Line data    Source code
       1              : import 'dart:io';
       2              : import 'dart:math';
       3              : 
       4              : class TestainersUtils {
       5            0 :   static Map<String, String> loadEnv({
       6              :     String envFile = '.env',
       7              :     bool mergeWithPlatform = true,
       8              :   }) {
       9            0 :     final Map<String, String> env = <String, String>{};
      10              : 
      11            0 :     final File file = File(envFile);
      12              : 
      13            0 :     if (file.existsSync()) {
      14            0 :       final List<String> lines = file.readAsLinesSync();
      15              : 
      16            0 :       for (int i = 0; i < lines.length; i++) {
      17            0 :         final String line = lines[i];
      18              : 
      19            0 :         if (line.trim().startsWith('#')) {
      20              :           continue;
      21              :         }
      22              : 
      23            0 :         final List<String> parts = line.split('=');
      24              : 
      25            0 :         if (parts.length < 2) {
      26              :           continue;
      27              :         }
      28              : 
      29            0 :         if (parts.first.isEmpty) {
      30              :           continue;
      31              :         }
      32              : 
      33            0 :         String value = parts.getRange(1, parts.length).join('=');
      34              : 
      35            0 :         if (value.isEmpty) {
      36              :           continue;
      37              :         }
      38              : 
      39            0 :         if (value.trim().startsWith('"')) {
      40            0 :           final StringBuffer buffer = StringBuffer(value);
      41              : 
      42            0 :           while (!buffer.toString().trim().endsWith('"')) {
      43            0 :             i++;
      44              : 
      45            0 :             if (i >= lines.length) {
      46            0 :               buffer.write('"');
      47              :               continue;
      48              :             }
      49              : 
      50              :             buffer
      51            0 :               ..write('\n')
      52            0 :               ..write(lines[i]);
      53              :           }
      54              : 
      55            0 :           value = buffer.toString().trim();
      56              : 
      57            0 :           value = value.substring(1, value.length - 1).replaceAll(r'\n', '\n');
      58              :         } else {
      59            0 :           value = value.trim();
      60              :         }
      61              : 
      62            0 :         env[parts.first.trim()] = value;
      63              :       }
      64              :     }
      65              : 
      66              :     if (mergeWithPlatform) {
      67            0 :       env.addAll(Platform.environment);
      68              :     }
      69              : 
      70              :     return env;
      71              :   }
      72              : 
      73            7 :   static Future<int> generatePort({InternetAddress? address}) async {
      74              :     final RawServerSocket socket =
      75           14 :         await RawServerSocket.bind(address ?? InternetAddress.loopbackIPv4, 0);
      76            7 :     final int port = socket.port;
      77            7 :     await socket.close();
      78              :     return port;
      79              :   }
      80              : 
      81            9 :   static String generateName() {
      82            9 :     final List<String> animalList = <String>[
      83              :       'alligator',
      84              :       'alpaca',
      85              :       'ant',
      86              :       'armadillo',
      87              :       'badger',
      88              :       'bat',
      89              :       'bear',
      90              :       'beaver',
      91              :       'bee',
      92              :       'buffalo',
      93              :       'butterfly',
      94              :       'camel',
      95              :       'capybara',
      96              :       'caribou',
      97              :       'cat',
      98              :       'cheetah',
      99              :       'chimpanzee',
     100              :       'chinchilla',
     101              :       'chipmunk',
     102              :       'cobra',
     103              :       'cow',
     104              :       'coyote',
     105              :       'crab',
     106              :       'crocodile',
     107              :       'deer',
     108              :       'dog',
     109              :       'dolphin',
     110              :       'donkey',
     111              :       'dragonfly',
     112              :       'duck',
     113              :       'eagle',
     114              :       'elephant',
     115              :       'emu',
     116              :       'falcon',
     117              :       'ferret',
     118              :       'fish',
     119              :       'flamingo',
     120              :       'fox',
     121              :       'frog',
     122              :       'gazelle',
     123              :       'gecko',
     124              :       'giraffe',
     125              :       'goat',
     126              :       'goldfish',
     127              :       'gorilla',
     128              :       'hamster',
     129              :       'hedgehog',
     130              :       'hippopotamus',
     131              :       'hornet',
     132              :       'horse',
     133              :       'iguana',
     134              :       'jackal',
     135              :       'jaguar',
     136              :       'jellyfish',
     137              :       'kangaroo',
     138              :       'kitten',
     139              :       'koala',
     140              :       'lamb',
     141              :       'lemur',
     142              :       'leopard',
     143              :       'lion',
     144              :       'lizard',
     145              :       'llama',
     146              :       'lobster',
     147              :       'lynx',
     148              :       'macaw',
     149              :       'marmot',
     150              :       'meerkat',
     151              :       'mink',
     152              :       'mongoose',
     153              :       'moose',
     154              :       'mosquito',
     155              :       'mouse',
     156              :       'octopus',
     157              :       'opossum',
     158              :       'orangutan',
     159              :       'otter',
     160              :       'owl',
     161              :       'ox',
     162              :       'panda',
     163              :       'pangolin',
     164              :       'panther',
     165              :       'parrot',
     166              :       'peacock',
     167              :       'pelican',
     168              :       'penguin',
     169              :       'pig',
     170              :       'platypus',
     171              :       'puma',
     172              :       'quokka',
     173              :       'raccoon',
     174              :       'rat',
     175              :       'reindeer',
     176              :       'rhinoceros',
     177              :       'salamander',
     178              :       'scorpion',
     179              :       'seahorse',
     180              :       'seal',
     181              :       'shark',
     182              :       'sheep',
     183              :       'skunk',
     184              :       'sloth',
     185              :       'snail',
     186              :       'snake',
     187              :       'spider',
     188              :       'squirrel',
     189              :       'starfish',
     190              :       'swan',
     191              :       'tapir',
     192              :       'termite',
     193              :       'tiger',
     194              :       'tortoise',
     195              :       'toucan',
     196              :       'turtle',
     197              :       'vulture',
     198              :       'walrus',
     199              :       'weasel',
     200              :       'whale',
     201              :       'wolf',
     202              :       'wombat',
     203              :       'yak',
     204              :       'zebra',
     205              :     ];
     206              : 
     207            9 :     final List<String> adjectiveList = <String>[
     208              :       'acrobatic',
     209              :       'adorable',
     210              :       'agile',
     211              :       'beautiful',
     212              :       'busy',
     213              :       'busy',
     214              :       'camouflaged',
     215              :       'camouflaged',
     216              :       'charming',
     217              :       'colorful',
     218              :       'cunning',
     219              :       'curious',
     220              :       'elegant',
     221              :       'elusive',
     222              :       'endangered',
     223              :       'energetic',
     224              :       'ferocious',
     225              :       'ferocious',
     226              :       'fierce',
     227              :       'gentle',
     228              :       'graceful',
     229              :       'gracious',
     230              :       'hardy',
     231              :       'inquisitive',
     232              :       'intelligent',
     233              :       'lively',
     234              :       'magnificent',
     235              :       'majestic',
     236              :       'majestic',
     237              :       'nocturnal',
     238              :       'playful',
     239              :       'playful',
     240              :       'powerful',
     241              :       'prickly',
     242              :       'resourceful',
     243              :       'scaly',
     244              :       'sensitive',
     245              :       'silent',
     246              :       'slithery',
     247              :       'sly',
     248              :       'sociable',
     249              :       'social',
     250              :       'strong',
     251              :       'swift',
     252              :       'swift',
     253              :       'vibrant',
     254              :       'vocal',
     255              :       'wild',
     256              :       'wise',
     257              :       'adaptable',
     258              :       'alert',
     259              :       'ambitious',
     260              :       'amusing',
     261              :       'brave',
     262              :       'bright',
     263              :       'calm',
     264              :       'careful',
     265              :       'clever',
     266              :       'confident',
     267              :       'cooperative',
     268              :       'courageous',
     269              :       'creative',
     270              :       'daring',
     271              :       'determined',
     272              :       'diligent',
     273              :       'disciplined',
     274              :       'eager',
     275              :       'efficient',
     276              :       'faithful',
     277              :       'famous',
     278              :       'friendly',
     279              :       'funny',
     280              :       'generous',
     281              :       'gentle',
     282              :       'happy',
     283              :       'helpful',
     284              :       'honest',
     285              :       'humorous',
     286              :       'imaginative',
     287              :       'independent',
     288              :       'innovative',
     289              :       'intuitive',
     290              :       'kind',
     291              :       'knowledgeable',
     292              :       'likeable',
     293              :       'loving',
     294              :       'loyal',
     295              :       'modest',
     296              :       'neat',
     297              :       'nice',
     298              :       'obedient',
     299              :       'optimistic',
     300              :       'organized',
     301              :       'patient',
     302              :       'persistent',
     303              :       'pioneering',
     304              :       'polite',
     305              :       'popular',
     306              :       'practical',
     307              :       'quick',
     308              :       'quiet',
     309              :       'reliable',
     310              :       'reserved',
     311              :       'resourceful',
     312              :       'romantic',
     313              :       'self-confident',
     314              :       'self-disciplined',
     315              :       'sensible',
     316              :       'sensitive',
     317              :       'shy',
     318              :       'sincere',
     319              :       'smart',
     320              :       'sociable',
     321              :       'straightforward',
     322              :       'sympathetic',
     323              :       'thoughtful',
     324              :       'tidy',
     325              :       'tough',
     326              :       'trustworthy',
     327              :       'unassuming',
     328              :       'understanding',
     329              :       'versatile',
     330              :       'warmhearted',
     331              :       'willing',
     332              :       'witty',
     333              :     ];
     334              : 
     335           45 :     return '${animalList[Random().nextInt(animalList.length)]}-'
     336           36 :         '${adjectiveList[Random().nextInt(adjectiveList.length)]}';
     337              :   }
     338              : }
        

Generated by: LCOV version 2.0-1