feeds from empty struct
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"show-rss/src/db"
|
||||
"show-rss/src/feeds"
|
||||
"strconv"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
@@ -13,41 +12,15 @@ 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")
|
||||
id, err := feeds.Insert(ctx, "url", "cron")
|
||||
if err != nil {
|
||||
t.Fatal("cannot insert:", err)
|
||||
}
|
||||
|
||||
got, err := f.Get(ctx, id)
|
||||
got, err := feeds.Get(ctx, id)
|
||||
if err != nil {
|
||||
t.Fatal("cannot get:", err)
|
||||
}
|
||||
@@ -83,11 +56,11 @@ func TestFeeds(t *testing.T) {
|
||||
t.Error("execution.version")
|
||||
}
|
||||
|
||||
if err := f.Executed(ctx, got.Entry.ID, got.Version.Created); err != nil {
|
||||
if err := feeds.Executed(ctx, got.Entry.ID, got.Version.Created); err != nil {
|
||||
t.Fatal("cannot executed:", err)
|
||||
}
|
||||
|
||||
got2, err := f.Get(ctx, id)
|
||||
got2, err := feeds.Get(ctx, id)
|
||||
if err != nil {
|
||||
t.Fatal("cannot get w executed:", err)
|
||||
}
|
||||
@@ -105,10 +78,10 @@ func TestFeeds(t *testing.T) {
|
||||
t.Errorf("changes after execution: was \n\t%+v but now \n\t%+v", got, got2)
|
||||
}
|
||||
|
||||
if err := f.Executed(ctx, got.Entry.ID, got.Version.Created); err != nil {
|
||||
if err := feeds.Executed(ctx, got.Entry.ID, got.Version.Created); err != nil {
|
||||
t.Fatal("cannot executed again:", err)
|
||||
}
|
||||
got3, err := f.Get(ctx, id)
|
||||
got3, err := feeds.Get(ctx, id)
|
||||
if err != nil {
|
||||
t.Fatal("cannot get w executed again:", err)
|
||||
} else if got2.Execution == got3.Execution {
|
||||
@@ -116,7 +89,7 @@ func TestFeeds(t *testing.T) {
|
||||
}
|
||||
|
||||
n := 0
|
||||
if err := f.ForEach(ctx, func(feed feeds.Feed) error {
|
||||
if err := feeds.ForEach(ctx, func(feed feeds.Feed) error {
|
||||
n += 1
|
||||
if feed != got3 {
|
||||
t.Errorf("for each yielded difference than last get")
|
||||
|
||||
Reference in New Issue
Block a user