Skip to content
Snippets Groups Projects
  1. Jun 28, 2023
    • Will McCutchen's avatar
      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
  2. Jun 26, 2023
  3. Jun 21, 2023
  4. Jun 18, 2023
    • Bill Mill's avatar
      fix: return empty data field for empty request bodies (#125) · a70a8478
      Bill Mill authored
      When a request to `/anything` has an empty body, the `data` field of the
      output should be the empty string. Currently, `go-httpbin is returning
      `data:application/octet-stream;base64,`.
      
      - Should the output actually be null? That would match `files`, `form`,
      and `json`, but also would require deeper changes since `Data` is stored
      as a string not a pointer, and I didn't want to mess with things any
      more than I had to. An empty string works fine for my purposes
      - how can I test this PR? I tried but I got confused by the TestAnything
      method
      - all the current tests pass under this change
      
      This PR closes #124. Before:
      
      ```
      $ curl -s 'http://0.0.0.0:8080/anything?one=two'
      {
        "args": {
          "one": [
            "two"
          ]
        },
        "headers": {
          "Accept": [
            "*/*"
          ],
          "Host": [
            "0.0.0.0:8080"
          ],
          "User-Agent": [
            "curl/7.88.1"
          ]
        },
        "method": "GET",
        "origin": "127.0.0.1:60402",
        "url": "http://0.0.0.0:8080/anything?one=two",
        "data": "data:application/octet-stream;base64,",
        "files": null,
        "form": null,
        "json": null
      }
      ```
      
      After:
      ```
      $ curl -s 'http://0.0.0.0:8080/anything?one=two'
      {
        "args": {
          "one": [
            "two"
          ]
        },
        "headers": {
          "Accept": [
            "*/*"
          ],
          "Host": [
            "0.0.0.0:8080"
          ],
          "User-Agent": [
            "curl/7.88.1"
          ]
        },
        "method": "GET",
        "origin": "127.0.0.1:60595",
        "url": "http://0.0.0.0:8080/anything?one=two",
        "data": "",
        "files": null,
        "form": null,
        "json": null
      }
      ```
    • Bill Mill's avatar
      feat: add method property to responses (#123) · 1223a736
      Bill Mill authored
      ```console
      # before: httpbingo lacks the "method" field but httpbin.org has it
      $ curl -s https://httpbingo.org/anything | jq .method                                                                                                        9:31PM
      null
      $ curl -s https://httpbin.org/anything | jq .method
      "GET"
      
      # after: httpbingo has the method field!
      $ curl -s http://0.0.0.0:8080/anything | jq .method
      "GET"
      ```
      
      This was mentioned in #6, but then not listed in #91
      
      - I took the highly technical testing approach of adding a test for
      `Method` anywhere in `handlers_test.go` that mentioned `Args`; do you
      desire more tests? fewer tests?
      - Anywhere else I should add this field that I didn't already?
      
      For what it's worth, I discovered this when working on upgrading the
      testing for our [httpsnippet
      library](https://github.com/readmeio/httpsnippet); I wanted to use
      `go-httpbin` but our tests expect the method field to be present in the
      responses
      1223a736
  5. May 05, 2023
  6. May 02, 2023
  7. Mar 13, 2023
  8. Feb 15, 2023
  9. Jan 31, 2023
  10. Jan 17, 2023
  11. Nov 19, 2022
    • Will McCutchen's avatar
      Improve tests for streaming response endpoints (#105) · 1229cc69
      Will McCutchen authored
      A few small improvements to the test suite:
      - Ensure `/stream` and `/stream-bytes` endpoints actually use
      `Transfer-Encoding: chunked`, instead of inferring/hoping based on
      Content-Length header
      - Explicitly test that `/drip` actually does sleep between writing
      bytes, rather than inferring that it does based on entire response
      duration
      1229cc69
  12. Nov 16, 2022
  13. Nov 13, 2022
  14. Nov 11, 2022
  15. Oct 19, 2022
    • Will McCutchen's avatar
      More comprehensive tests for HTTP verb endpoints (#88) · 4ec6c82f
      Will McCutchen authored
      We were not explicitly testing the behavior of some HTTP verb endpoints
      like /put and /patch, because they currently share an underlying handler
      with /post which is thoroughly tested.
      
      The addition of the /anything endpoint in #83 made me realize a bit more
      explicit test coverage would be good, so here we're landing a bit of a
      refactoring of the test suite to generate tests for all of those
      endpoints.
      
      Along the way, we also improve compatibility with the original httpbin
      implementation by tricking the stdlib net/http machinery into parsing
      request bodies for DELETE requests.
      4ec6c82f
  16. Oct 17, 2022
  17. Jul 24, 2022
  18. Jul 08, 2022
  19. Jul 05, 2022
  20. Apr 01, 2022
  21. Mar 31, 2022
    • Will McCutchen's avatar
      Misc build & CI fixes (#76) · e154d05c
      Will McCutchen authored
      * Fix installation of deps
      
      * Rebuild static assets w/ newest go-bindata
      
      * Update go versions for CI
      
      * Fix deploy on merge
      
      * Bump golangci-lint version
      e154d05c
  22. Jan 04, 2022
  23. Nov 29, 2021
  24. Jul 16, 2021
  25. Jul 13, 2021
  26. May 10, 2021
  27. May 05, 2021
  28. Apr 21, 2021
  29. Jan 20, 2021
Loading