newsbot-api/internal/services/cron/scheduler_test.go

72 lines
1.2 KiB
Go
Raw Normal View History

package cron_test
import (
"context"
"database/sql"
"testing"
2024-04-23 07:15:38 -07:00
"git.jamestombleson.com/jtom38/newsbot-api/internal/services/cron"
_ "github.com/glebarez/go-sqlite"
"github.com/pressly/goose/v3"
)
func TestCheckReddit(t *testing.T) {
db, err := setupInMemoryDb()
if err != nil {
t.Log(err)
t.FailNow()
}
defer db.Close()
ctx := context.Background()
c := cron.NewScheduler(ctx, db)
c.CheckReddit()
}
func TestCheckYouTube(t *testing.T) {
db, err := setupInMemoryDb()
if err != nil {
t.Log(err)
t.FailNow()
}
defer db.Close()
ctx := context.Background()
c := cron.NewScheduler(ctx, db)
c.CheckYoutube()
}
func TestCheckTwitch(t *testing.T) {
db, err := setupInMemoryDb()
if err != nil {
t.Log(err)
t.FailNow()
}
defer db.Close()
ctx := context.Background()
c := cron.NewScheduler(ctx, db)
err = c.CheckTwitch()
if err != nil {
t.Error(err)
}
}
func setupInMemoryDb() (*sql.DB, error) {
db, err := sql.Open("sqlite", ":memory:")
if err != nil {
return nil, err
}
err = goose.SetDialect("sqlite3")
if err != nil {
return nil, err
}
err = goose.Up(db, "../database/migrations")
if err != nil {
return nil, err
}
return db, nil
}