feeds tests pass
This commit is contained in:
56
src/feeds/db_test.go
Normal file
56
src/feeds/db_test.go
Normal 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)
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user