Files
ai_site/platform/internal/dbsync/push_test.go
whm b04b180d30 feat: harden loose-offline sync for user JWT, schema, and console ops
Enable Binding-scoped agent push/pull, empty-table schema ensure, SyncPage inspect/drop-table, default module import, and agent-bound publish docs from the 宇恒联调意见.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-05 09:47:35 +08:00

48 lines
1.2 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package dbsync
import "testing"
func TestNormalizePushPayloadInsert(t *testing.T) {
op, payload, pk, err := normalizePushPayload(PushItem{
Op: "insert",
RowPK: "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
Row: map[string]any{
"id": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
"name": "x",
},
}, "id")
if err != nil {
t.Fatal(err)
}
if op != "upsert" || pk == "" || payload == "" {
t.Fatalf("got op=%s pk=%s payload=%s", op, pk, payload)
}
}
func TestNormalizePushPayloadDelete(t *testing.T) {
op, payload, pk, err := normalizePushPayload(PushItem{
Op: "delete",
RowPK: "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
}, "id")
if err != nil {
t.Fatal(err)
}
if op != "delete" || pk == "" || payload == "" {
t.Fatalf("got op=%s pk=%s payload=%s", op, pk, payload)
}
}
func TestTableInChannel(t *testing.T) {
ch := &Channel{
Local: Endpoint{Tables: []string{"orders"}},
Remote: Endpoint{Tables: []string{"orders"}},
}
// Z4通道表白名单不再拒收
if !tableInChannel(ch, "orders") || !tableInChannel(ch, "other") {
t.Fatal("expected any non-empty table accepted")
}
if tableInChannel(ch, "") {
t.Fatal("empty table rejected")
}
}