Esempio n. 1
0
func TestThreadRepository_GetByIDWithComments(t *testing.T) {
	db := LoadFixtures(MigrateUp(GetDB(t), t), t)
	threadRepository := &gonews.ThreadRepository{DB: db, Logger: gonews.NewDefaultLogger(gonews.OFF)}
	thread, err := threadRepository.GetByIDWithComments(1)
	Expect(t, err, nil)
	Expect(t, thread.AuthorID, int64(1), "thread.AuthorID")
}
Esempio n. 2
0
func TestThreadRepository_GetByAuthorID(t *testing.T) {
	db := LoadFixtures(MigrateUp(GetDB(t), t), t)

	threadRepository := &gonews.ThreadRepository{DB: db, Logger: gonews.NewDefaultLogger(gonews.OFF)}
	threads, err := threadRepository.GetByAuthorID(1, 1000, 0)
	Expect(t, err, nil)
	Expect(t, len(threads), 2, "len(threads)")
	Expect(t, threads[0].ID, int64(1), "threads[0].ID")
	Expect(t, threads[0].AuthorID, int64(1), "threads[0].AuthorID")
}
Esempio n. 3
0
func TestCommentRepository_GetCommentsByAuthorID(t *testing.T) {
	db := LoadFixtures(MigrateUp(GetDB(t), t), t)
	count, authorId := 0, 1
	row := db.QueryRow("SELECT COUNT(ID) FROM comments_view WHERE AuthorID = ? ", int64(authorId))
	err := row.Scan(&count)
	Expect(t, err, nil)
	commentRepository := &gonews.CommentRepository{DB: db, Logger: gonews.NewDefaultLogger(gonews.OFF)}
	comments, err := commentRepository.GetCommentsByAuthorID(int64(authorId))
	Expect(t, err, nil)
	Expect(t, len(comments), count, "comments count")
}