cron testone tries nonempty
parent
baa97ab62d
commit
537eaf9801
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"show-rss/src/cmd/cron"
|
"show-rss/src/cmd/cron"
|
||||||
"show-rss/src/db"
|
"show-rss/src/db"
|
||||||
|
"show-rss/src/feeds"
|
||||||
"strconv"
|
"strconv"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
@ -13,24 +14,49 @@ func TestOne(t *testing.T) {
|
||||||
ctx, can := context.WithTimeout(context.Background(), 5*time.Second)
|
ctx, can := context.WithTimeout(context.Background(), 5*time.Second)
|
||||||
defer can()
|
defer can()
|
||||||
|
|
||||||
t.Run("same ctx", func(t *testing.T) {
|
for name, aCtx := range map[string]func() context.Context{
|
||||||
ctx := db.Test(t, ctx)
|
"empty": func() context.Context {
|
||||||
for i := 0; i < 2; i++ {
|
return db.Test(t, ctx)
|
||||||
t.Run(strconv.Itoa(i), func(t *testing.T) {
|
},
|
||||||
if err := cron.One(ctx); err != nil && ctx.Err() == nil {
|
"feeds": func() context.Context {
|
||||||
t.Fatalf("failed %d: %v", i, err)
|
ctx := db.Test(t, ctx)
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
t.Run("new ctx", func(t *testing.T) {
|
f, err := feeds.New(ctx)
|
||||||
for i := 0; i < 2; i++ {
|
if err != nil {
|
||||||
t.Run(strconv.Itoa(i), func(t *testing.T) {
|
t.Fatal(err)
|
||||||
if err := cron.One(db.Test(t, ctx)); err != nil && ctx.Err() == nil {
|
}
|
||||||
t.Fatalf("failed %d: %v", i, 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)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue