Skip to content

TimothyStiles/ditto

Repository files navigation

ditto

Ditto is a dead simple code-gen free, mock free, CLI tool free, API call caching package for testing 3rd party APIs in Go.

You shouldn't have to mock 3rd party APIs to test your code. Ditto caches API responses for you to use in your tests.

All you have to do is replace your API client's http.Client with ditto.Client when writing your tests and you're good to go. Ditto checks if the request has been made before and if so, returns the cached response. If not, it makes the request and caches the response for you to run your tests against later on.

Install

go get github.com/TimothyStiles/ditto

Usage

ditto/example_test.go

Lines 11 to 24 in da8d0f0

func Example_basic() {
client := github.NewClient(ditto.Client()) // instead of http.DefaultClient we use ditto.Client()
// Use client...
repos, _, err := client.Repositories.List(context.Background(), "octocat", nil)
if err != nil {
fmt.Println("Error:", err)
return
}
fmt.Println(repos[0].GetName())
// Output: boysenberry-repo-1
}