-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpodcast_test.go
37 lines (32 loc) · 905 Bytes
/
podcast_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package devtogo
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/stretchr/testify/require"
)
func TestPodcastEpisodes(t *testing.T) {
var res PodcastEpisodes
b := unmarshalGoldenFileBytes(t, "podcasts.json", &res)
tests := []struct {
name string
arguments Arguments
expectedQueryParams string
}{
{"No params", Defaults(), ""},
{"Page param", Arguments{"page": "1"}, "page=1"},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
require.Equal(t, "/podcast_episodes?"+test.expectedQueryParams, r.URL.String())
w.WriteHeader(http.StatusOK)
w.Write(b)
}))
client := NewClient(withBaseURL(ts.URL))
pe, err := client.PodcastEpisodes(test.arguments)
require.NoError(t, err)
require.Equal(t, res, pe)
})
}
}