forked from rjelierse/go-tvapis
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from mrobinsn/cleanup
Cleanup
- Loading branch information
Showing
5 changed files
with
93 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
language: go | ||
|
||
go: | ||
- tip | ||
- stable | ||
before_install: | ||
- go get -u github.com/mattn/goveralls | ||
script: | ||
- go vet ./... | ||
- goveralls -race -v -show -service=travis-ci |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,105 +1,95 @@ | ||
package tvmaze | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
|
||
log "github.com/Sirupsen/logrus" | ||
. "github.com/smartystreets/goconvey/convey" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestTVMaze(t *testing.T) { | ||
log.SetLevel(log.DebugLevel) | ||
Convey("I have setup a TVMaze client", t, func() { | ||
c := DefaultClient | ||
c := DefaultClient | ||
|
||
Convey("I can find a show", func() { | ||
results, err := c.FindShows("archer") | ||
So(err, ShouldBeNil) | ||
So(len(results), ShouldBeGreaterThan, 0) | ||
//fmt.Println(JSONString(results)) | ||
So(results[0].Show.GetTitle(), ShouldNotBeBlank) | ||
So(results[0].Show.GetDescription(), ShouldNotBeBlank) | ||
}) | ||
t.Run("find show", func(t *testing.T) { | ||
t.Parallel() | ||
results, err := c.FindShows("archer") | ||
require.NoError(t, err) | ||
require.NotEmpty(t, results, "expected results") | ||
require.NotEmpty(t, results[0].Show.GetTitle()) | ||
require.NotEmpty(t, results[0].Show.GetDescription()) | ||
}) | ||
|
||
Convey("I can get a show by its tvmaze id", func() { | ||
result, err := c.GetShowWithID("315") // Archer | ||
So(err, ShouldBeNil) | ||
So(result, ShouldNotBeNil) | ||
//fmt.Println(JSONString(result)) | ||
So(result.GetTitle(), ShouldEqual, "Archer") | ||
So(result.GetDescription(), ShouldNotBeBlank) | ||
So(result.GetTVDBID(), ShouldEqual, 110381) | ||
So(result.GetTVRageID(), ShouldEqual, 23354) | ||
So(result.GetIMDBID(), ShouldEqual, "tt1486217") | ||
So(result.GetMediumPoster(), ShouldNotBeBlank) | ||
So(result.GetOriginalPoster(), ShouldNotBeBlank) | ||
}) | ||
t.Run("get show by id", func(t *testing.T) { | ||
t.Parallel() | ||
result, err := c.GetShowWithID("315") // Archer | ||
require.NoError(t, err) | ||
require.NotNil(t, result, "expected a result") | ||
require.Equal(t, "Archer", result.GetTitle()) | ||
require.NotEmpty(t, result.GetDescription()) | ||
require.Equal(t, 110381, result.GetTVDBID()) | ||
require.Equal(t, 23354, result.GetTVRageID()) | ||
require.Equal(t, "tt1486217", result.GetIMDBID()) | ||
require.NotEmpty(t, result.GetMediumPoster()) | ||
require.NotEmpty(t, result.GetOriginalPoster()) | ||
}) | ||
|
||
Convey("I can get a specific episode of a show", func() { | ||
result, err := c.GetEpisode(Show{ID: 315}, 4, 5) | ||
So(err, ShouldBeNil) | ||
So(result, ShouldNotBeNil) | ||
So(result.Name, ShouldNotBeBlank) | ||
So(result.Summary, ShouldNotBeBlank) | ||
}) | ||
t.Run("get episode", func(t *testing.T) { | ||
t.Parallel() | ||
result, err := c.GetEpisode(Show{ID: 315}, 4, 5) | ||
require.NoError(t, err) | ||
require.NotNil(t, result, "expected a result") | ||
require.NotEmpty(t, result.Name) | ||
require.NotEmpty(t, result.Summary) | ||
}) | ||
|
||
Convey("I can get a show by its tvrage id", func() { | ||
result, err := c.GetShowWithTVRageID("23354") // Archer | ||
So(err, ShouldBeNil) | ||
So(result, ShouldNotBeNil) | ||
//fmt.Println(JSONString(result)) | ||
So(result.GetTitle(), ShouldNotBeBlank) | ||
So(result.GetDescription(), ShouldNotBeBlank) | ||
}) | ||
t.Run("get show with tvrage id", func(t *testing.T) { | ||
t.Parallel() | ||
result, err := c.GetShowWithTVRageID("23354") // Archer | ||
require.NoError(t, err) | ||
require.NotNil(t, result, "expected a result") | ||
require.NotEmpty(t, result.GetTitle()) | ||
require.NotEmpty(t, result.GetDescription()) | ||
}) | ||
|
||
Convey("I can get a show", func() { | ||
result, err := c.GetShow("archer") | ||
So(err, ShouldBeNil) | ||
So(result, ShouldNotBeNil) | ||
//fmt.Println(JSONString(result)) | ||
So(result.GetTitle(), ShouldNotBeBlank) | ||
So(result.GetDescription(), ShouldNotBeBlank) | ||
}) | ||
t.Run("get show by name", func(t *testing.T) { | ||
t.Parallel() | ||
result, err := c.GetShow("archer") | ||
require.NoError(t, err) | ||
require.NotNil(t, result, "expected a result") | ||
require.NotEmpty(t, result.GetTitle()) | ||
require.NotEmpty(t, result.GetDescription()) | ||
}) | ||
|
||
Convey("I can refresh a show", func() { | ||
show := Show{ID: 315} // Archer | ||
err := c.RefreshShow(&show) | ||
So(err, ShouldBeNil) | ||
So(show.GetTitle(), ShouldNotBeBlank) | ||
So(show.GetDescription(), ShouldNotBeBlank) | ||
}) | ||
t.Run("refresh show", func(t *testing.T) { | ||
t.Parallel() | ||
show := Show{ID: 315} // Archer | ||
err := c.RefreshShow(&show) | ||
|
||
Convey("I can get episodes for a show", func() { | ||
show := Show{ID: 315} // Archer | ||
episodes, err := c.GetEpisodes(show) | ||
So(err, ShouldBeNil) | ||
//fmt.Println(JSONString(episodes)) | ||
So(len(episodes), ShouldBeGreaterThan, 0) | ||
}) | ||
require.NoError(t, err) | ||
require.NotEmpty(t, show.GetTitle()) | ||
require.NotEmpty(t, show.GetDescription()) | ||
}) | ||
|
||
Convey("I can get the next episode for a show", func() { | ||
show := Show{ID: 82} // Game of Thrones | ||
episode, err := c.GetNextEpisode(show) | ||
So(err, ShouldBeNil) | ||
So(episode, ShouldNotBeNil) | ||
//fmt.Println(JSONString(episode)) | ||
}) | ||
t.Run("get episodes", func(t *testing.T) { | ||
t.Parallel() | ||
show := Show{ID: 315} // Archer | ||
episodes, err := c.GetEpisodes(show) | ||
require.NoError(t, err) | ||
require.NotEmpty(t, episodes, "expected to get episodes") | ||
}) | ||
|
||
Convey("null times are parsed correctly", func() { | ||
show := Show{ID: 180} // Firefly | ||
episodes, err := c.GetEpisodes(show) | ||
So(err, ShouldBeNil) | ||
//fmt.Println(JSONString(episodes)) | ||
So(len(episodes), ShouldBeGreaterThan, 0) | ||
}) | ||
t.Run("get next episode", func(t *testing.T) { | ||
t.Parallel() | ||
show := Show{ID: 1864} // Superstore | ||
episode, err := c.GetNextEpisode(show) | ||
require.NoError(t, err) | ||
require.NotNil(t, episode) | ||
}) | ||
} | ||
|
||
func JSONString(val interface{}) string { | ||
bytes, err := json.MarshalIndent(val, "", " ") | ||
if err != nil { | ||
panic(err) | ||
} | ||
return string(bytes) | ||
t.Run("null times", func(t *testing.T) { | ||
t.Parallel() | ||
show := Show{ID: 180} // Firefly | ||
episodes, err := c.GetEpisodes(show) | ||
require.NoError(t, err) | ||
require.NotEmpty(t, episodes, "expected to get episodes") | ||
}) | ||
} |