37 lines
576 B
Go
37 lines
576 B
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestStorage(t *testing.T) {
|
|
ctx, can := context.WithTimeout(context.Background(), time.Second)
|
|
defer can()
|
|
|
|
db := NewTestDBIn(t.TempDir())
|
|
defer db.Close()
|
|
|
|
s := NewStorage(db)
|
|
|
|
if _, err := s.Get(ctx, "id"); err != ErrNotFound {
|
|
t.Error("failed to get 404", err)
|
|
}
|
|
|
|
m := Message{
|
|
ID: "id",
|
|
TS: 1,
|
|
}
|
|
|
|
if err := s.Upsert(ctx, m); err != nil {
|
|
t.Error("failed to upsert", err)
|
|
}
|
|
|
|
if m2, err := s.Get(ctx, "id"); err != nil {
|
|
t.Error("failed to get", err)
|
|
} else if m != m2 {
|
|
t.Error(m2)
|
|
}
|
|
}
|