Add db uuid4 func and uuid insert message param

This commit is contained in:
dwrz
2026-10-09 16:52:31 +00:00
parent f365ccad16
commit e8b239649a
3 changed files with 65 additions and 1 deletions
+48
View File
@@ -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)