36 lines
1.2 KiB
Go
36 lines
1.2 KiB
Go
package v071
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
)
|
|
|
|
func TestChunkSequenceProjectionKeepsContent(t *testing.T) {
|
|
for _, restore := range []bool{false, true} {
|
|
target := &ProductionLibraryTarget{scope: ProductionScope{TenantID: 10001, KnowledgeBaseID: "kb-target"}, snapshotTenant: 10002, snapshotKB: "kb-source", preserveChunkSequence: restore}
|
|
row := map[string]json.RawMessage{"id": json.RawMessage(`"chunk-src"`), "tenant_id": json.RawMessage(`10002`), "knowledge_base_id": json.RawMessage(`"kb-source"`), "seq_id": json.RawMessage(`7`), "content": json.RawMessage(`"exact content"`)}
|
|
if err := target.rowTransform("chunks")(row); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
_, present := row["seq_id"]
|
|
if present != restore {
|
|
t.Fatalf("restore=%v seq_id present=%v", restore, present)
|
|
}
|
|
if string(row["content"]) != `"exact content"` || string(row["id"]) != `"chunk-src"` {
|
|
t.Fatal("content identity was changed")
|
|
}
|
|
before, err := canonicalRowDigest(row)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
row["content"] = json.RawMessage(`"corrupted"`)
|
|
after, err := canonicalRowDigest(row)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if before == after {
|
|
t.Fatal("content corruption was hidden")
|
|
}
|
|
}
|
|
}
|