Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Flute - Golang HTTP Client testing framework

Flute - Golang HTTP Client testing framework

I introduce my OSS `flute`, which is the HTTP client testing framework for Golang.
https://github.com/suzuki-shunsuke/flute

Shunsuke Suzuki

July 13, 2019
Tweet

More Decks by Shunsuke Suzuki

Other Decks in Programming

Transcript

  1. Overview • Introduction of my OSS `flute`, which is the

    HTTP client testing framework for Golang • How to test HTTP request parameters and mock the API server 3
  2. Tests of the API client Request parameters • HTTP method,

    request path, query, header, request body, etc Response • parse of response body 6
  3. Tests of the API client Request parameters • HTTP method,

    request path, query, header, request body, etc Response • parse of response body They are common to all API clients, so letʼs do them at the framework 7
  4. Other libraries in awesome-go There are many libraries for testing

    of HTTP clients. • https://github.com/avelino/awesome-go#testing • https://github.com/h2non/gock • https://github.com/seborama/govcr • https://github.com/jarcoal/httpmock • https://github.com/tv42/mockhttp • https://github.com/gavv/httpexpect • https://github.com/dnaeon/go-vcr • https://github.com/h2non/baloo • etc 8
  5. So why do I develop flute? • We can mock

    the HTTP server with them, but we canʼt test the request parameters with them • I used gock, but it is inconvenient that we canʼt understand why the request matches no mock 9
  6. So why do I develop flute? • We can mock

    the HTTP server with them, but we canʼt test the request parameters with them • I used gock, but it is inconvenient that we canʼt understand why the request matches no mock I canʼt find the library meets my needs completely, so I decided to develop it by myself 10
  7. How to write the mock server in Go • run

    the mock server with httptest • customize http.Clientʼs Transport 11
  8. How to write the mock server in Go • run

    the mock server with httptest • customize http.Clientʼs Transport <- flute choices this 12
  9. Features • tests of request parameters • HTTP method, request

    path, query, header, request body, etc • mock the HTTP server 14
  10. 18

  11. 19 1. match the request with Matcher 2. test the

    request with Tester 3. returns the response with Response
  12. assertion of the request parameters flute uses testify internally, so

    it is easy to understand why the test fails 21
  13. Conclusion • I develop the OSS `flute`, which is the

    HTTP client testing framework for Golang • With flute we can not only mock the API server but also test the request parameters • With flute we can define the tests declaratively • In Go, we can mock the HTTP server easily with http.RoundTripper 23