feeds tests pass

This commit is contained in:
bel
2025-04-25 21:41:52 -06:00
parent d77e35596e
commit a2d1d17e23
4 changed files with 263 additions and 66 deletions

56
src/feeds/db_test.go Normal file
View File

@@ -0,0 +1,56 @@
package feeds_test
import (
"context"
"show-rss/src/db"
"show-rss/src/feeds"
"strconv"
"testing"
"time"
)
func TestFeeds(t *testing.T) {
ctx, can := context.WithTimeout(context.Background(), 5*time.Second)
defer can()
t.Run("same ctx", func(t *testing.T) {
ctx := db.Test(t, ctx)
for i := 0; i < 2; i++ {
t.Run(strconv.Itoa(i), func(t *testing.T) {
if _, err := feeds.New(ctx); err != nil && ctx.Err() == nil {
t.Fatalf("failed %d: %v", i, err)
}
})
}
})
t.Run("new ctx", func(t *testing.T) {
for i := 0; i < 2; i++ {
t.Run(strconv.Itoa(i), func(t *testing.T) {
if _, err := feeds.New(db.Test(t, ctx)); err != nil && ctx.Err() == nil {
t.Fatalf("failed %d: %v", i, err)
}
})
}
})
t.Run("crud", func(t *testing.T) {
ctx := db.Test(t, ctx)
f, err := feeds.New(ctx)
if err != nil && ctx.Err() == nil {
t.Fatalf("failed: %v", err)
}
id, err := f.Insert(ctx, "url", "cron")
if err != nil {
t.Fatal("cannot insert:", err)
}
got, err := f.Get(ctx, id)
if err != nil {
t.Fatal("cannot get:", err)
}
t.Errorf("%+v", got)
})
}