2020-10-05 08:24:33 +00:00
|
|
|
package postgres
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2020-10-10 17:08:06 +00:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"1bet.fr/scraper/news"
|
|
|
|
"1bet.fr/scraper/utils"
|
2020-10-05 08:24:33 +00:00
|
|
|
)
|
|
|
|
|
2020-10-10 17:08:06 +00:00
|
|
|
var n *news.News
|
|
|
|
|
2020-10-05 08:24:33 +00:00
|
|
|
func TestConnect(t *testing.T) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-10-10 17:08:06 +00:00
|
|
|
func TestListLeagues(t *testing.T) {
|
|
|
|
leagues, err := ListLeagues()
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("unexpected error : %s", err)
|
|
|
|
}
|
|
|
|
if len(leagues) == 0 {
|
|
|
|
t.Errorf("no league got from ListLeagues function")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-05 08:24:33 +00:00
|
|
|
func TestListSources(t *testing.T) {
|
|
|
|
sources, err := ListSources()
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("unexpected error : %s", err)
|
|
|
|
}
|
|
|
|
if len(sources) == 0 {
|
2020-10-10 17:08:06 +00:00
|
|
|
t.Errorf("no source got from ListSources function")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestInsertNews(t *testing.T) {
|
|
|
|
tags := []string{"Test", "Hello Toto"}
|
|
|
|
cleanTags := []string{"test", "hello-toto"}
|
|
|
|
nowTime := time.Now()
|
|
|
|
n = &news.News{
|
|
|
|
Source: &news.Source{Id: 1, Sport: &news.Sport{Id: 1}},
|
|
|
|
PubDate: &nowTime,
|
|
|
|
Link: "https://test.com/toto",
|
|
|
|
Title: "Hello toto",
|
|
|
|
CleanTitle: "hello-toto",
|
|
|
|
Tags: &tags,
|
|
|
|
CleanTags: &cleanTags,
|
|
|
|
}
|
|
|
|
err := InsertNews(n)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
if n.Id == 0 {
|
|
|
|
t.Errorf("unexpected value 0 for n.Id")
|
2020-10-05 08:24:33 +00:00
|
|
|
}
|
2020-10-10 17:08:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestUpdateNews(t *testing.T) {
|
|
|
|
content := []string{"toto", "test"}
|
|
|
|
n.Content = &content
|
|
|
|
n.Author = utils.StringPointer("T. Toto")
|
|
|
|
updated, err := UpdateNews(n)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
if updated != 1 {
|
|
|
|
t.Errorf("unexpected %d update rows", updated)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDeleteNews(t *testing.T) {
|
|
|
|
deleted, err := DeleteNews(n)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
if deleted != 1 {
|
|
|
|
t.Errorf("unexpected %d news deleted", deleted)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClose(t *testing.T) {
|
|
|
|
Close()
|
|
|
|
}
|