Skip to content

Instantly share code, notes, and snippets.

@sonya
Created November 4, 2021 02:42
Show Gist options
  • Save sonya/3ea4f2bcebfcaed2c8c3cf7be7f62f34 to your computer and use it in GitHub Desktop.
Save sonya/3ea4f2bcebfcaed2c8c3cf7be7f62f34 to your computer and use it in GitHub Desktop.
http request mocking code samples
func TestGetFixedValue(t *testing.T) {
defer gock.Off()
gock.New("https://example.com/fixedvalue").
MatchHeader("Accept", "application/json").
Get("/").
Reply(200).
JSON(map[string]string{"value": "fixed"})
value, _ := GetFixedValue("https://example.com")
if value != "fixed" {
t.Errorf("Expected 'fixed', got %s", value)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment