James Tombleson
75b66dd625
* Using sqlc to generate queries and goose for migrations. The intial tests look good. * moving the old calls away for now. Might use this in a package later on. * Added postgres driver * Updated the dockerfile to support sql migrations * added sqlc config file * updated schema and starting a seed script * updated models to use the database ones * updated reddit cron to talk to the db * added env for sql connection string * got the reddit source working with the db and posting articles * added sql packages * added rule to ignore dev sql file * added migration down statement for rolling back * updated cron for reddit and youtube * Updated reddit to follow a new standard pattern * updated youtube to follow new patterns * updated tests and brought them to the standard * updated the seed migration * all cron tasks should feed the db now * updated app init * bumped docker to 1.18.3 * disabled remote tests given secrets and lack of interfaces currently to run tests
110 lines
2.8 KiB
Go
110 lines
2.8 KiB
Go
package services_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/jtom38/newsbot/collector/database"
|
|
"github.com/jtom38/newsbot/collector/services"
|
|
)
|
|
|
|
var YouTubeRecord database.Source = database.Source{
|
|
ID: uuid.New(),
|
|
Name: "dadjokes",
|
|
Source: "reddit",
|
|
Site: "reddit",
|
|
Url: "https://youtube.com/gamegrumps",
|
|
}
|
|
|
|
func TestGetPageParser(t *testing.T) {
|
|
yc := services.NewYoutubeClient(YouTubeRecord)
|
|
_, err := yc.GetParser(YouTubeRecord.Url)
|
|
if err != nil { panic(err) }
|
|
}
|
|
|
|
func TestGetChannelId(t *testing.T) {
|
|
yc := services.NewYoutubeClient(YouTubeRecord)
|
|
parser, err := yc.GetParser(YouTubeRecord.Url)
|
|
if err != nil { panic(err) }
|
|
|
|
_, err = yc.GetChannelId(parser)
|
|
if err != nil { panic(err) }
|
|
}
|
|
|
|
func TestPullFeed(t *testing.T) {
|
|
yc := services.NewYoutubeClient(YouTubeRecord)
|
|
parser, err := yc.GetParser(YouTubeRecord.Url)
|
|
if err != nil { panic(err) }
|
|
|
|
_, err = yc.GetChannelId(parser)
|
|
if err != nil { panic(err) }
|
|
|
|
_, err = yc.PullFeed()
|
|
if err != nil { panic(err) }
|
|
}
|
|
|
|
func TestGetAvatarUri(t *testing.T) {
|
|
yc := services.NewYoutubeClient(YouTubeRecord)
|
|
res, err := yc.GetAvatarUri()
|
|
if err != nil { panic(err) }
|
|
if res == "" { panic(services.ErrMissingAuthorImage)}
|
|
}
|
|
|
|
func TestGetVideoTags(t *testing.T) {
|
|
yc := services.NewYoutubeClient(YouTubeRecord)
|
|
|
|
var videoUri = "https://www.youtube.com/watch?v=k_sQEXOBe68"
|
|
|
|
parser, err := yc.GetParser(videoUri)
|
|
if err != nil { panic(err) }
|
|
|
|
tags, err := yc.GetTags(parser)
|
|
if err == nil && tags == "" { panic("err was empty but value was missing.")}
|
|
if err != nil { panic(err) }
|
|
}
|
|
|
|
func TestGetChannelTags(t *testing.T) {
|
|
yc := services.NewYoutubeClient(YouTubeRecord)
|
|
|
|
parser, err := yc.GetParser(YouTubeRecord.Url)
|
|
if err != nil { panic(err) }
|
|
|
|
tags, err := yc.GetTags(parser)
|
|
if err == nil && tags == "" { panic("no err but expected value was missing.")}
|
|
if err != nil { panic(err) }
|
|
}
|
|
|
|
func TestGetVideoThumbnail(t *testing.T) {
|
|
yc := services.NewYoutubeClient(YouTubeRecord)
|
|
parser, err := yc.GetParser("https://www.youtube.com/watch?v=k_sQEXOBe68")
|
|
if err != nil {panic(err) }
|
|
|
|
thumb, err := yc.GetVideoThumbnail(parser)
|
|
if err == nil && thumb == "" { panic("no err but expected result was missing")}
|
|
if err != nil { panic(err) }
|
|
|
|
}
|
|
|
|
func TestCheckSource(t *testing.T) {
|
|
yc := services.NewYoutubeClient(YouTubeRecord)
|
|
_, err := yc.GetContent()
|
|
if err != nil { panic(err) }
|
|
}
|
|
|
|
func TestCheckUriCache(t *testing.T) {
|
|
yc := services.NewYoutubeClient(YouTubeRecord)
|
|
item := "demo"
|
|
|
|
services.YoutubeUriCache = append(services.YoutubeUriCache, &item)
|
|
res := yc.CheckUriCache(&item)
|
|
if res == false { panic("expected a value to come back")}
|
|
}
|
|
|
|
func TestCheckUriCacheFails(t *testing.T) {
|
|
yc := services.NewYoutubeClient(YouTubeRecord)
|
|
item := "demo1"
|
|
|
|
res := yc.CheckUriCache(&item)
|
|
if res == true { panic("expected no value to come back")}
|
|
|
|
} |