WIP/init
This commit is contained in:
69
repo_test.go
Normal file
69
repo_test.go
Normal file
@@ -0,0 +1,69 @@
|
||||
package outbox_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
|
||||
"code.uint32.ru/tiny/outbox"
|
||||
)
|
||||
|
||||
type My struct {
|
||||
A string
|
||||
B int
|
||||
}
|
||||
|
||||
func TestOutboxMethods(t *testing.T) {
|
||||
db, err := sql.Open("sqlite3", "test.db")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
defer os.Remove("test.db")
|
||||
defer db.Close()
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
box, err := outbox.OpenOrCreate[My](ctx, db)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
one := My{
|
||||
A: "hello",
|
||||
B: 42,
|
||||
}
|
||||
|
||||
if err := box.Save(ctx, "test", &one); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
lst, err := box.GetPending(ctx, 100)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if len(lst) != 1 {
|
||||
t.Fatal("incorrect pending len")
|
||||
}
|
||||
|
||||
if err := box.MarkProcessed(ctx, "test"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
lst, err = box.GetPending(ctx, 100)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if len(lst) != 0 {
|
||||
t.Fatal("should be zero pending")
|
||||
}
|
||||
|
||||
if err := box.Cleanup(ctx); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user