Skip to content
Snippets Groups Projects
  • Will McCutchen's avatar
    0de8ec96
    Refactor test suite to make real requests to a real server (#131) · 0de8ec96
    Will McCutchen authored
    In the course of validating #125, we discovered that using the stdlib's
    [`httptest.ResponseRecorder`][0] mechanism to drive the vast majority of
    our unit tests led to some slight brokenness due to subtle differences
    in the way those "simulated" requests are handled vs "real" requests to
    a live HTTP server, as [explained in this comment][1].
    
    That prompted me to do a big ass refactor of the entire test suite,
    swapping httptest.ResponseRecorder for interacting with a live server
    instance via [`httptest.Server`][2].
    
    This should make the test suite more accurate and reliable in the long
    run by ensuring that the vast majority of tests are making actual HTTP
    requests and reading responses from the wire.
    
    Note that updating these tests also uncovered a few minor bugs in
    existing handler code, fixed in a separate commit for visibility.
    
    P.S. I'm awfully sorry to anyone who tries to merge or rebase local test
    changes after this refactor lands, that is goign to be a nightmare. If
    you run into issues resolving conflicts, feel free to ping me and I can
    try to help!
    
    [0]: https://pkg.go.dev/net/http/httptest#ResponseRecorder
    [1]: https://github.com/mccutchen/go-httpbin/pull/125#issuecomment-1596176645
    [2]: https://pkg.go.dev/net/http/httptest#Server
    0de8ec96
    History
    Refactor test suite to make real requests to a real server (#131)
    Will McCutchen authored
    In the course of validating #125, we discovered that using the stdlib's
    [`httptest.ResponseRecorder`][0] mechanism to drive the vast majority of
    our unit tests led to some slight brokenness due to subtle differences
    in the way those "simulated" requests are handled vs "real" requests to
    a live HTTP server, as [explained in this comment][1].
    
    That prompted me to do a big ass refactor of the entire test suite,
    swapping httptest.ResponseRecorder for interacting with a live server
    instance via [`httptest.Server`][2].
    
    This should make the test suite more accurate and reliable in the long
    run by ensuring that the vast majority of tests are making actual HTTP
    requests and reading responses from the wire.
    
    Note that updating these tests also uncovered a few minor bugs in
    existing handler code, fixed in a separate commit for visibility.
    
    P.S. I'm awfully sorry to anyone who tries to merge or rebase local test
    changes after this refactor lands, that is goign to be a nightmare. If
    you run into issues resolving conflicts, feel free to ping me and I can
    try to help!
    
    [0]: https://pkg.go.dev/net/http/httptest#ResponseRecorder
    [1]: https://github.com/mccutchen/go-httpbin/pull/125#issuecomment-1596176645
    [2]: https://pkg.go.dev/net/http/httptest#Server
This project manages its dependencies using Go Modules. Learn more