From 6a60ca3c6e54f76cfc72fbf9031af3895c9cc3c1 Mon Sep 17 00:00:00 2001 From: Nicolas Duhamel Date: Wed, 17 Feb 2016 20:02:55 +0100 Subject: [PATCH] Add show.NotFound error --- shows/shows.go | 7 +++++++ shows/shows_test.go | 8 +++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/shows/shows.go b/shows/shows.go index 80e7315..006efe9 100644 --- a/shows/shows.go +++ b/shows/shows.go @@ -29,6 +29,10 @@ const ( WHERE shows.imdbid=$1;` ) +var ( + NotFound = fmt.Errorf("Not found") +) + type Show struct { sqly.BaseTable polochon.Show @@ -41,6 +45,9 @@ func Get(db *sqlx.DB, imdbID string) (*Show, error) { s := &Show{} err := db.QueryRowx(getShowQuery, imdbID).StructScan(s) if err != nil { + if err.Error() == "sql: no rows in result set" { + return nil, NotFound + } return nil, err } return s, nil diff --git a/shows/shows_test.go b/shows/shows_test.go index 71422c3..e42e38a 100644 --- a/shows/shows_test.go +++ b/shows/shows_test.go @@ -85,6 +85,12 @@ func init() { func TestAddRemoveShow(t *testing.T) { sqly.RunWithLastestMigration(db, pgdsn, t, func(db *sqlx.DB, t *testing.T) { + //Get unkown show + _, err := Get(db, "polp") + if err != NotFound { + t.Fatal("NotFound error expected here") + } + nfo := strings.NewReader(showNFO1) s := &polochon.Show{} polochon.ReadNFO(nfo, s) @@ -102,7 +108,7 @@ func TestAddRemoveShow(t *testing.T) { show := Show{Show: *s} - err := show.Add(db) + err = show.Add(db) if err != nil { t.Fatal(err) }