diff --git a/tests/bot_test.go b/tests/bot_test.go index 23fadc87b7b0cb588490750da112b02216cec523..a88b811a805a9a5f4a9a3aba89b455adffade18c 100644 --- a/tests/bot_test.go +++ b/tests/bot_test.go @@ -9,49 +9,9 @@ import ( "git.iiens.net/morignot2011/playbot/site" ) -func TestAdd(t *testing.T) { - db := &DummyDb{} - bot := bot.NewPlayBot("test", db) - content, err := bot.Add("http://www.youtube.com/watch?v=IiWapK6WQPg", []string{"hardstle", "raw"}) - - if err != nil { - t.Fatalf("Receive error %s", err) - } - - if content.Author != "Delete" { - t.Error("invalid author") - } - - if content.Duration != 286 { - t.Error("invalid duration") - } - - // File - - if content.Source != "youtube" { - t.Error("invalid source") - } - - if content.SourceId != "IiWapK6WQPg" { - t.Error("invalid source id") - } - - if content.Title != "Warface & Delete - The Truth" { - t.Error("invalid title") - } - - if content.Url != "https://www.youtube.com/watch?v=IiWapK6WQPg" { - t.Error("invalid url") - } - - if db.createCalls[0] != content { - t.Error("invalid call to db.Create") - } -} - func TestExtractTags(t *testing.T) { db := &DummyDb{} - bot := bot.NewPlayBot("test", db) + bot := bot.NewPlayBot("test", db, []site.Reader{}) testCases := []struct { msg string diff --git a/tests/dummy.go b/tests/dummy.go index 2bc53d58b2fa726ce6bddaf5d1d17574fb99a5a6..4857b5ed3b6f1bf3069cefe9ef4c595f20b114aa 100644 --- a/tests/dummy.go +++ b/tests/dummy.go @@ -2,14 +2,41 @@ package test import ( "git.iiens.net/morignot2011/playbot/bot" - "git.iiens.net/morignot2011/playbot/site" ) type DummyDb struct { - createCalls []site.Content + insertCalls []interface{} + firstCalls []interface{} + modelCalls []interface{} + relatedCalls []interface{} + whereCalls []interface{} } -func (db *DummyDb) Create(value interface{}) bot.Db { - db.createCalls = append(db.createCalls, value.(site.Content)) +func (db *DummyDb) Error() error { + return nil +} + +func (db *DummyDb) Insert(value interface{}) bot.Db { + db.insertCalls = append(db.insertCalls, value) + return db +} + +func (db *DummyDb) First(value interface{}) bot.Db { + db.firstCalls = append(db.firstCalls, value) + return db +} + +func (db *DummyDb) Model(value interface{}) bot.Db { + db.modelCalls = append(db.modelCalls, value) + return db +} + +func (db *DummyDb) Related(value interface{}) bot.Db { + db.relatedCalls = append(db.relatedCalls, value) + return db +} + +func (db *DummyDb) Where(value interface{}) bot.Db { + db.whereCalls = append(db.whereCalls, value) return db } diff --git a/tests/mock.go b/tests/mock.go index f044181a2202e0f6aeb41326b480ca345e862004..841ec75c210523a63834b869bdd66c2ff4c8950e 100644 --- a/tests/mock.go +++ b/tests/mock.go @@ -3,6 +3,7 @@ package test import ( "sort" + "git.iiens.net/morignot2011/playbot/bot" "git.iiens.net/morignot2011/playbot/site" ) @@ -34,3 +35,11 @@ func (c *FakeCollection) Add(url string, tags []string) (site.Content, error) { func (*FakeCollection) Get() { } + +func (*FakeCollection) GetByUrl(url string) (*site.Content, error) { + return nil, nil +} + +func (*FakeCollection) InsertPost(*bot.Post) error { + return nil +}