コード例 #1
0
ファイル: tvmaze_test.go プロジェクト: gitter-badger/getme
func TestTvMazeSeasons(t *testing.T) {
	mux := http.NewServeMux()
	ts := httptest.NewServer(mux)
	defer ts.Close()

	mux.HandleFunc("/shows/1/episodes", func(w http.ResponseWriter, r *http.Request) {
		assert.Equal(t, "GET", r.Method)
		w.Header().Set("Content-Type", "application/json")
		fmt.Fprintln(w, readFixture("testdata/tvmaze_episodes.json"))
	})
	mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		require.False(t, true)
	})

	sources.SetTvMazeURL(ts.URL)

	seasons, err := (sources.TvMaze{}).Seasons(&store.Show{ID: 1})
	require.NoError(t, err)
	require.Len(t, seasons, 3)
	var season1 sources.Season
	for _, v := range seasons {
		if v.Season == 1 {
			season1 = v
		}
	}
	assert.Len(t, season1.Episodes, 13)
}
コード例 #2
0
ファイル: tvmaze_test.go プロジェクト: gitter-badger/getme
func TestTvMazeSearch(t *testing.T) {
	mux := http.NewServeMux()
	ts := httptest.NewServer(mux)
	defer ts.Close()

	mux.HandleFunc("/search/shows", func(w http.ResponseWriter, r *http.Request) {
		w.Header().Set("Content-Type", "application/json")
		fmt.Fprintln(w, readFixture("testdata/tvmaze_search.json"))
	})
	mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		require.False(t, true)
	})

	sources.SetTvMazeURL(ts.URL)

	results := (sources.TvMaze{}).Search("query")
	require.NoError(t, results.Error)
	require.Len(t, results.Shows, 10)
	assert.Equal(t, "Dead Set", results.Shows[0].Title)
}