best way to mock/unit test http.Client?

This page summarizes the projects mentioned and recommended in the original post on /r/golang

Our great sponsors
  • WorkOS - The modern identity platform for B2B SaaS
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • SaaSHub - Software Alternatives and Reviews
  • gock

    HTTP traffic mocking and testing made easy in Go ༼ʘ̚ل͜ʘ̚༽

  • github.com/h2non/gock

  • go-vcr

    Record and replay your HTTP interactions for fast, deterministic and accurate tests

  • dnaeon/go-vcr

  • WorkOS

    The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.

    WorkOS logo
  • gaia

    Build powerful pipelines in any programming language.

  • Something like this: https://github.com/gaia-pipeline/gaia/blob/8a9f66742fbb4c5120e52fcfeef94ff4fcfd63a0/workers/pipeline/git.go#L233

  • httpmock

    HTTP mocking for Golang

  • To mock an API: https://github.com/jarcoal/httpmock to use when your code calls external APIs so you don't want your tests call the real API. No need to create an interface as you do.

NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts