CodeSampleX

샘플

plug 1.20.3: Test a Plug router end to end with Plug.Test, with no HTTP server, no socket and no network

검증된 샘플 — hex plug 1.20.3: Test a Plug router end to end with Plug.Test, with no HTTP server, no socket and no network. elixir 1 · linux alpine/x64 · docker에서…

sha256:f7cb5b2f102e81a511f97af235bf61218cafe9e3bac8f599cb824293963da6c0

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. MIT-0

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
2
빌드한 서명 키
2
선언된 환경 elixir 1 linux x64 elixir 1 elixir mix

검증 실행 환경

환경 컨트랙트 단계 실행일
elixir 1 · linux alpine/x64 · docker ed25519:a2ec939a4c60e243 PASS compile:PASS · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · hex@1
2026-08-14
elixir 1 · linux alpine/x64 · docker ed25519:d91480838ac982c9 PASS compile:PASS · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · hex@1
2026-08-18

케이스

HOW
목표
Test a Plug router end to end with Plug.Test, with no HTTP server, no socket and no network
패키지
심벌
  • Plug.Test.conn
  • Plug.Test.sent_resp
  • Plug.Router
  • Plug.Parsers
  • Plug.Conn.send_resp
  • Plug.Conn.put_resp_content_type
  • Plug.Conn.AlreadySentError
  • Plug.Parsers.UnsupportedMediaTypeError
  • Plug.Conn.Unfetched
환경
elixir 1
생성일
2026-08-14T09:41:26Z

컨트랙트

  1. assert the test conn is an in-process struct with a fabricated loopback peer, and that the deprecated conn.owner field is nil because the owning pid lives in the adapter payload
  2. assert conn.status is nil and conn.state is :unset before the router runs, and 200/:sent after
  3. assert sent_resp reports a sent response and raises for one that resp/3 only staged
  4. assert a route binds its path segment as a variable in the route body
  5. assert an unmatched path is 404 only because match _ exists, and a router without it raises FunctionClauseError
  6. assert the method is part of the match, so a POST to a GET route falls through to 404
  7. assert Plug.Parsers is what turns a JSON body into conn.body_params, and that params merges the query string while body_params does not
  8. assert a top-level JSON array arrives under the _json key
  9. assert that without Plug.Parsers body_params stays Plug.Conn.Unfetched, which raises ArgumentError on a bare conn but reads back as nil through a router because :match overwrites conn.params
  10. assert a content type listed in :pass reaches a route unparsed with body_params still the Unfetched placeholder, while one in neither :parsers nor :pass raises Plug.Parsers.UnsupportedMediaTypeError
  11. assert a map body passed to conn/3 is written straight into body_params as multipart/mixed, skipping the parser entirely, and that read_body returns a placeholder
  12. assert send_resp and put_resp_header raise Plug.Conn.AlreadySentError once the response is sent
  13. assert put_resp_content_type appends charset=utf-8 and stores a lowercase header name that get_resp_header matches exactly

파일

  • csx.json
  • lib/csx_plug/raw_router.ex
  • lib/csx_plug/router.ex
  • mix.exs
  • mix.lock
  • test/contract_test.exs
  • test/test_helper.exs

소스 아티팩트 내려받기 (tar.gz)

오리진 시더

anonymous