move lastfm mock client stuff to a new package so we can reuse it

for the artistcache test
This commit is contained in:
sentriz
2023-09-14 00:00:47 +01:00
parent c374577328
commit a15b584fda
9 changed files with 82 additions and 104 deletions

View File

@@ -9,6 +9,7 @@ import (
_ "github.com/mattn/go-sqlite3"
"github.com/stretchr/testify/require"
"go.senan.xyz/gonic/db"
"go.senan.xyz/gonic/scrobble/lastfm/mockclient"
)
func TestScrobble(t *testing.T) {
@@ -44,7 +45,7 @@ func TestScrobble(t *testing.T) {
stamp := time.Date(2023, 8, 12, 12, 34, 1, 200, time.UTC)
httpClient, shutdown := httpClientMock(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
client := Client{mockclient.New(t, func(w http.ResponseWriter, r *http.Request) {
require.Equal(http.MethodPost, r.Method)
require.Equal(url.Values{
"album": []string{"album1"},
@@ -64,12 +65,10 @@ func TestScrobble(t *testing.T) {
require.Equal(baseURL, "https://"+r.Host+r.URL.Path)
w.WriteHeader(http.StatusOK)
w.Write([]byte(artistGetTopTracksResponse))
}))
defer shutdown()
w.Write(mockclient.ArtistGetTopTracksResponse)
})}
client := &Client{&httpClient}
scrobbler := NewScrobbler(testDB, client)
scrobbler := NewScrobbler(testDB, &client)
// act
err = scrobbler.Scrobble(user, track, stamp, true)
@@ -78,7 +77,7 @@ func TestScrobble(t *testing.T) {
require.NoError(err)
}
func TestScrobble_returnsWithoutLastFMSession(t *testing.T) {
func TestScrobbleReturnsWithoutLastFMSession(t *testing.T) {
// arrange
t.Parallel()
require := require.New(t)
@@ -92,7 +91,7 @@ func TestScrobble_returnsWithoutLastFMSession(t *testing.T) {
require.NoError(err)
}
func TestScrobble_failsWithoutLastFMAPIKey(t *testing.T) {
func TestScrobbleFailsWithoutLastFMAPIKey(t *testing.T) {
// arrange
t.Parallel()
require := require.New(t)