2022-05-15 21:48:23 -07:00
|
|
|
package cron_test
|
|
|
|
|
2022-06-08 21:17:08 -07:00
|
|
|
import (
|
|
|
|
"context"
|
2024-04-29 16:29:54 -07:00
|
|
|
"database/sql"
|
2022-06-08 21:17:08 -07:00
|
|
|
"testing"
|
|
|
|
|
2024-04-23 07:15:38 -07:00
|
|
|
"git.jamestombleson.com/jtom38/newsbot-api/internal/services/cron"
|
2024-04-29 16:29:54 -07:00
|
|
|
_ "github.com/glebarez/go-sqlite"
|
|
|
|
"github.com/pressly/goose/v3"
|
2022-06-08 21:17:08 -07:00
|
|
|
)
|
2022-05-15 21:48:23 -07:00
|
|
|
|
2022-06-08 21:17:08 -07:00
|
|
|
func TestCheckReddit(t *testing.T) {
|
2024-04-29 16:29:54 -07:00
|
|
|
db, err := setupInMemoryDb()
|
|
|
|
if err != nil {
|
|
|
|
t.Log(err)
|
|
|
|
t.FailNow()
|
|
|
|
}
|
|
|
|
defer db.Close()
|
|
|
|
|
2022-06-08 21:17:08 -07:00
|
|
|
ctx := context.Background()
|
2024-04-29 16:29:54 -07:00
|
|
|
c := cron.NewScheduler(ctx, db)
|
2022-06-30 14:54:58 -07:00
|
|
|
c.CheckReddit()
|
2022-06-08 21:17:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestCheckYouTube(t *testing.T) {
|
2024-04-29 16:29:54 -07:00
|
|
|
db, err := setupInMemoryDb()
|
|
|
|
if err != nil {
|
|
|
|
t.Log(err)
|
|
|
|
t.FailNow()
|
|
|
|
}
|
|
|
|
defer db.Close()
|
|
|
|
|
2022-06-08 21:17:08 -07:00
|
|
|
ctx := context.Background()
|
2024-04-29 16:29:54 -07:00
|
|
|
c := cron.NewScheduler(ctx, db)
|
2022-06-30 14:54:58 -07:00
|
|
|
c.CheckYoutube()
|
2022-06-08 21:17:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestCheckTwitch(t *testing.T) {
|
2024-04-29 16:29:54 -07:00
|
|
|
db, err := setupInMemoryDb()
|
|
|
|
if err != nil {
|
|
|
|
t.Log(err)
|
|
|
|
t.FailNow()
|
|
|
|
}
|
|
|
|
defer db.Close()
|
|
|
|
|
2022-06-08 21:17:08 -07:00
|
|
|
ctx := context.Background()
|
2024-04-29 16:29:54 -07:00
|
|
|
c := cron.NewScheduler(ctx, db)
|
|
|
|
err = c.CheckTwitch()
|
2022-06-08 21:17:08 -07:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2022-05-15 21:48:23 -07:00
|
|
|
}
|
2024-04-29 16:29:54 -07:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|