zmb3 / spotify

A Go wrapper for the Spotify Web API
Apache License 2.0
1.34k stars 284 forks source link

Proper way to mock `Client` #133

Closed seiyab closed 3 years ago

seiyab commented 3 years ago

How to test apps that uses this wrapper? I'm happy if documents exist or an official interface and mock implementations are provided. Now I define my own interface and inject mock like following.

// example

type SpotifyClient interface {
  GetTracks(ids ...spotify.ID) ([]*spotify.FullTrack, error)
  ...
}

// in test code
type mockSpotifyClient struct {}

func (c *mockSpotifyClient) GetTracks(ids ...spotify.ID) ([]*spotify.FullTrack, error) {
  ...
}
strideynet commented 3 years ago

Defining your own interfaces is the go way. This is not a concern of the library.