Skip to content

Add unit tests for HTTP/1.1 parsing functions in docker_client.zig#2

Merged
dragosv merged 2 commits intounixsocketfrom
copilot/sub-pr-1
Feb 24, 2026
Merged

Add unit tests for HTTP/1.1 parsing functions in docker_client.zig#2
dragosv merged 2 commits intounixsocketfrom
copilot/sub-pr-1

Conversation

Copy link

Copilot AI commented Feb 24, 2026

Description

Adds 22 unit tests covering the custom HTTP/1.1 client implementation in src/docker_client.zig. Tests use a pipeStream() helper that wraps a pre-filled POSIX pipe as std.net.Stream, enabling fully isolated testing without a real Docker socket.

HttpReader

  • readByte: ordering, EndOfStream at EOF
  • readExact: exact reads, EndOfStream on insufficient data
  • readLine: CRLF/LF endings, null on empty EOF, partial data without newline, error.HttpHeaderTooLong on buffer overflow

parseResponseHead

  • 200/404 status codes, Content-Length, chunked Transfer-Encoding
  • Error cases: empty input, missing space, truncated status code
  • Robustness: skips headers without :, case-insensitive names

readChunkedBody

  • Single/multiple chunks, empty body, chunk extensions (;), optional trailers, invalid chunk size (returns accumulated data)

readUntilClose

  • Full stream, empty stream, data pre-buffered in HttpReader.buf

sendHttpRequest

  • GET request line and mandatory headers
  • POST with Content-Type, Content-Length, and body appended

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring
  • Performance improvement
  • Test addition/modification
  • CI/CD changes

Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Testing

  • Unit tests

Tests run via zig build test --summary all. No Docker daemon required — all tests are pure unit tests using POSIX pipes as mock streams.

Additional Notes

The pipeStream() helper writes test data to a pipe's write end and closes it before returning the read end as a std.net.Stream. On both Linux and macOS, std.net.Stream.handle is i32, matching posix.fd_t, so pipe fds can be used directly.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: dragosv <422243+dragosv@users.noreply.github.com>
Copilot AI changed the title [WIP] Address feedback on unix sockets implementation Add unit tests for HTTP/1.1 parsing functions in docker_client.zig Feb 24, 2026
Copilot AI requested a review from dragosv February 24, 2026 09:54
@dragosv dragosv marked this pull request as ready for review February 24, 2026 14:38
@dragosv dragosv merged commit 89adad0 into unixsocket Feb 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants