Repository navigation
test: cover HTTP JSON transport behavior - #15
Merged
NetworkTheoryAppliedResearchInstitute merged 1 commit intoOct 28, 2026
Merged
NetworkTheoryAppliedResearchInstitute merged 1 commit into
NetworkTheoryAppliedResearchInstitute merged 1 commit into
Conversation
Signed-off-by: Nirmal Khedkar <nirmalhk7@gmail.com>
nirmalhk7
force-pushed
the
nirmal/httpjson-transport-tests
branch
from
October 24, 2026 19:32
084778f to
3447711
Compare
nirmalhk7
marked this pull request as ready for review
October 24, 2026 19:58
NetworkTheoryAppliedResearchInstitute
approved these changes
Oct 28, 2026
NetworkTheoryAppliedResearchInstitute
left a comment
Contributor
There was a problem hiding this comment.
Hi Nirmal, thanks for this. It's a solid, test-only PR that gives transport/httpjson real coverage where it had none.
What I tested (head 3447711)
- CI ran on GitHub's merge commit aefcfc6, which is your head merged into current main 4e52c35. All checks passed: gofmt, go vet, go build, go test ./..., conformance (55/55 ALL MATCH), the zero-dependency check and DCO.
- transport/httpjson now reports "ok" instead of "[no test files]". The other packages give the same results as on main.
- I read both new files. Your count of 52 cases matches the code.
- I couldn't run Go tests locally, so these results come from CI on Linux. CI runs
go test ./...without-race, so I couldn't reproduce your race-detector run. Reading the code, I don't see a race.
What's good
The assertions are strict, not just "no error":
- assertCoordinatorCall checks exact routing: one call, the right method and a DeepEqual of the input.
- The
node +/&?=雪node_id tests query escaping end to end. - trackedBody checks that every response body is closed.
- The 4096-byte error limit is checked by exact length.
- Every POST is checked for its request Content-Type.
- The year-10000 timestamp exercises the marshal error path.
- All 25 bad requests are checked to never reach the coordinator.
- The exact 500 body is checked.
Everything stays stdlib-only, and the fake hosts use .test.
Small follow-ups (none block this PR)
- transport/httpjson/server.go:80: no test checks the 204 that SPEC.md:393-398 says POST routes return, or the 200 for GET. Changing or deleting the WriteHeader still passes. Suggested fix: add a success arm to TestHandlerReturnsCoordinatorErrors that expects 204 with an empty body for POST routes and 200 for /v0/jobs and /v0/fees.
- client_test.go:83-94, :98, :124: the cancellation and transport-error tests cover only listing, jobs and fees. Suggested fix: add heartbeat, decline and report cases to invokeRequest and the two method lists.
- server.go:38, :51, :76: nothing checks that r.Context() reaches the coordinator, because recordingCoordinator ignores its ctx. Suggested fix: record ctx and assert a context.WithValue marker set with httptest.NewRequest(...).WithContext(...).
- client.go:75: nothing tests status 300 (the upper edge of the 2xx check). Suggested fix: add a case with status 300, body "moved" and expected error "sohocloud: GET /v0/jobs: status 300: moved".
- Optional, server.go:93: the response Content-Type isn't asserted. This only matters if SPEC starts requiring it.
Thanks again for the careful work.
Approved at the tested commit 3447711 on Jodson Graves's instruction.
NetworkTheoryAppliedResearchInstitute
merged commit Oct 28, 2026
91e182f
into
NTARI-RAND:main
4 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The HTTP+JSON transport had no test coverage. Add 52 test cases covering client/server round trips for all six coordinator operations, request rejection, and error handling. Transport statement coverage rises from 0% to 100%.
The tests exercise query escaping for node IDs, byte and timestamp serialization, default and supplied HTTP clients, malformed request/response JSON, missing node IDs, unsupported methods, coordinator failures, cancellation, transport errors, response-body closure, and the 4096-byte error-body limit.
Only two test files change. Production code, dependencies, CI, and quality configuration remain unchanged.
Validation:
go test -race -count=1 -coverprofile=/tmp/protocol-httpjson-final-coverage.out ./...: passes; HTTP transport has 100% statement coverage.go vet ./...,go build ./..., and repository-widegofmtcheck: pass.python3 testdata/reproduce_spec.py: all 55 checks match.git diff --check: passes.