cron testone tries nonempty

main
Bel LaPointe 2025-04-27 11:33:59 -06:00
parent baa97ab62d
commit 537eaf9801
1 changed files with 43 additions and 17 deletions

View File

@ -4,6 +4,7 @@ import (
"context"
"show-rss/src/cmd/cron"
"show-rss/src/db"
"show-rss/src/feeds"
"strconv"
"testing"
"time"
@ -13,24 +14,49 @@ func TestOne(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 := cron.One(ctx); err != nil && ctx.Err() == nil {
t.Fatalf("failed %d: %v", i, err)
}
})
}
})
for name, aCtx := range map[string]func() context.Context{
"empty": func() context.Context {
return db.Test(t, ctx)
},
"feeds": func() context.Context {
ctx := db.Test(t, ctx)
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 := cron.One(db.Test(t, ctx)); err != nil && ctx.Err() == nil {
t.Fatalf("failed %d: %v", i, err)
f, err := feeds.New(ctx)
if err != nil {
t.Fatal(err)
}
for i := 0; i < 2; i++ {
if _, err := f.Insert(ctx, strconv.Itoa(i), "* * * * *"); err != nil {
t.Fatal(err)
}
}
return ctx
},
} {
name := name
aCtx := aCtx
t.Run(name, func(t *testing.T) {
t.Run("same ctx", func(t *testing.T) {
ctx := aCtx()
for i := 0; i < 2; i++ {
t.Run(strconv.Itoa(i), func(t *testing.T) {
if err := cron.One(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) {
ctx := aCtx()
if err := cron.One(ctx); err != nil && ctx.Err() == nil {
t.Fatalf("failed %d: %v", i, err)
}
})
}
})
})
}
}