CodeSampleX

Exemple

http 1.6.0: Test code that calls an HTTP API with package:http using MockClient, with no network, and see what the client actually sends and decodes

Échantillon vérifié pour pub http 1.6.0: Test code that calls an HTTP API with package:http using MockClient, with no network, and see what the client…

sha256:ed3c594714b9ed323ec4da016bdf6f9e47b615cc78872cab62588dd0532e98b7

Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré. Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes. MIT-0

Preuves d'exécution

L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.

Base de preuve
Contrat signé réussi
Reçus de vérification
2
Clés de signature qui l’ont compilé
2
Environnement déclaré dart 3 linux x64 dart 3 dart pub

Environnements des exécutions de vérification

Environnement Contrat Étapes Exécution
dart 3 · linux alpine/x64 · docker ed25519:a2ec939a4c60e243 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · pub@1
2026-08-14
dart 3 · linux debian/x64 · docker ed25519:2175b912ea1c23b1 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · pub@1
2026-08-18

Cas

HOW
Objectif
Test code that calls an HTTP API with package:http using MockClient, with no network, and see what the client actually sends and decodes
Paquets
Symboles
  • MockClient
  • Client.get
  • Client.post
  • Client.read
  • Response.body
  • Response.bodyBytes
  • Request.bodyFields
  • MultipartRequest
  • ClientException
Environnement
dart 3
Créé
2026-08-14T09:40:43Z

Contrat

  1. assert the MockClient handler receives the finalized request the client built, with its url and query, headers that look up case-insensitively but keep the case you wrote, and an empty GET body
  2. assert the handler argument is a rebuilt plain Request rather than your object, so a MultipartRequest arrives flattened to its encoded body and boundary header, and the request you sent comes back finalized
  3. assert a 404 does not throw from get: the Future completes, the error body decodes like any payload, and only statusCode and reasonPhrase report it
  4. assert read and readBytes are the exception and throw a ClientException at status 400 and above, with the server's error body no longer reachable, while 399 is read back as a body
  5. assert response.body decodes application/json without a charset as utf8 but falls back to latin1 for text/plain, text/html, application/xml, a vendor +json subtype and a missing content-type, while bodyBytes stays raw
  6. assert a Map body is form-encoded as application/x-www-form-urlencoded with percent-encoded utf8 and no charset parameter appended
  7. assert a declared JSON content-type stays exactly application/json with utf8 bytes on the wire, while an undeclared String body is announced as text/plain; charset=utf-8 and a declared application/xml gains charset=utf-8
  8. assert passing a Map under a JSON content-type throws StateError from Request.bodyFields instead of silently mis-encoding
  9. assert a ClientException thrown by the handler propagates unwrapped with its message and uri, and any other exception type propagates with its own type

Fichiers

  • csx.json
  • lib/users.dart
  • pubspec.lock
  • pubspec.yaml
  • test/contract_test.dart

Télécharger l’artefact source (tar.gz)

Seeder d'origine

anonymous