Checking for invalid category
This commit is contained in:
parent
0658b245d2
commit
44efcabb06
2 changed files with 31 additions and 1 deletions
10
gomdb.go
10
gomdb.go
|
@ -151,10 +151,18 @@ func MovieByImdbID(id string) (*MovieResult, error) {
|
|||
func requestAPI(apiCategory string, params ...string) (resp *http.Response, err error) {
|
||||
var URL *url.URL
|
||||
URL, err = url.Parse(baseURL)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Checking for invalid category
|
||||
if len(params) > 1 && params[2] != "" {
|
||||
if params[2] != MovieSearch &&
|
||||
params[2] != SeriesSearch &&
|
||||
params[2] != EpisodeSearch {
|
||||
return nil, errors.New("Invalid search category- " + params[2])
|
||||
}
|
||||
}
|
||||
URL.Path += "/"
|
||||
parameters := url.Values{}
|
||||
switch apiCategory {
|
||||
|
|
|
@ -61,6 +61,28 @@ func TestFailSearch(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestInvalidCategory(t *testing.T) {
|
||||
tests := []struct {
|
||||
query *QueryData
|
||||
}{
|
||||
{&QueryData{Title: "Game of Thrones", Year: "2001", SearchType: "bad"}},
|
||||
{&QueryData{Title: "Dexter", SearchType: "bad"}},
|
||||
}
|
||||
|
||||
for i, item := range tests {
|
||||
_, err := Search(item.query)
|
||||
if err == nil {
|
||||
t.Errorf("Test[%d]: Got nil error", i)
|
||||
continue
|
||||
}
|
||||
// Checking for strings is bad. But the error type is formatted
|
||||
if err.Error() != "Invalid search category- bad" {
|
||||
t.Errorf("Test[%d]: Unexpected value- %s, Got- %s", i, err)
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestMovieByTitle(t *testing.T) {
|
||||
tests := []struct {
|
||||
query *QueryData
|
||||
|
|
Loading…
Reference in a new issue