Add db uuid4 func and uuid insert message param
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"log/slog"
|
||||
"reflect"
|
||||
"testing"
|
||||
"uuid"
|
||||
|
||||
"github.com/mattn/go-sqlite3"
|
||||
)
|
||||
@@ -344,6 +345,53 @@ func testMessaging(t *testing.T, ctx context.Context, db *SQLite) {
|
||||
}
|
||||
})
|
||||
}
|
||||
suppliedID := uuid.NewV4()
|
||||
for _, tt := range []struct {
|
||||
name string
|
||||
id *uuid.UUID
|
||||
wantErr bool
|
||||
}{
|
||||
{name: "generated ID"},
|
||||
{name: "supplied v4 ID", id: &suppliedID},
|
||||
{name: "duplicate ID", id: &suppliedID, wantErr: true},
|
||||
} {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
seq, err := qw.NextSequence(ctx, c.Id)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
inserted, err := qw.InsertMessage(ctx, InsertMessageParams{
|
||||
Content: `{"role":"assistant","content":"answer"}`,
|
||||
ConversationId: c.Id,
|
||||
Id: tt.id,
|
||||
Role: MessageRoleAssistant,
|
||||
Sequence: seq,
|
||||
})
|
||||
if tt.wantErr {
|
||||
if err == nil {
|
||||
t.Fatal("duplicate ID was accepted")
|
||||
}
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := uuid.Parse(inserted.Id); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if tt.id != nil && inserted.Id != tt.id.String() {
|
||||
t.Errorf("inserted ID = %s, want %s", inserted.Id, tt.id.String())
|
||||
}
|
||||
if tt.id == nil {
|
||||
if err := qw.DeleteMessageId(ctx, inserted.Id); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
if err := qw.DeleteMessageId(ctx, suppliedID.String()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
tx, err := db.Writer.BeginTx(ctx, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
Reference in New Issue
Block a user