Files
mesh-delivery/modules/mesh-delivery-indexer/internal/index/pushed_test.go
T
jschoubben 88285ad5e2 B5g7-2: the indexer takes a pushed message alike with a merged one
Its head stands where a merged message's merge stands: forgeKind, pending refs, the newest load and the revision's head.

Builds: design 47 G §509, §714, A-269

Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
2026-11-12 10:18:01 +01:00

47 lines
2.0 KiB
Go

package index
import (
"context"
"encoding/json"
"testing"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-forge-bridge/forgemsg"
)
// Design 47 G §509, §714, A-269: a pushed message's head stands where a merged message's merge stands: the pending value keeps
// it as its ref, the newest load reads it from the bridge's answer and the pending value read back holds it alike.
func TestAPushedMessageStandsInTheRevisionWhereAMergedMessageDoes(t *testing.T) {
b := newTakeInBed(t)
head := "5555555555555555555555555555555555555555"
pushed := b.base
pushed.Kind, pushed.Number, pushed.Merge, pushed.Base, pushed.Branch, pushed.Head = forgemsg.ForgePushed, 0, "", "", "feat/x", head
data, err := forgemsg.EncodeForge(pushed)
if err != nil {
t.Fatal(err)
}
b.bridge[pushed.Repository+"@"+head] = data // the bridge answers by the head, where a merge's commit would stand
f := RevisionForm(pushed)
if f.Kind != forgemsg.ForgeMerged || f.Merge != head {
t.Fatalf("RevisionForm = %s %q, want a merged form at the head", f.Kind, f.Merge)
}
value, err := encodePending(Pending{Seq: 9, Ref: refOf(f)})
if err != nil {
t.Fatal(err)
}
_, got, err := DecodePending(value)
if err != nil || got.Merge != head {
t.Fatalf("DecodePending of the ref = %+v, %v, want the head as its merge", got, err)
}
// A value an earlier indexer wrote with the pushed message whole reads alike.
whole, _ := json.Marshal(Pending{V: 1, Seq: 9, Forge: data})
if _, got, err = DecodePending(whole); err != nil || got.Merge != head || got.Kind != forgemsg.ForgeMerged {
t.Fatalf("DecodePending of the whole message = %+v, %v", got, err)
}
// The load reads the bridge's pushed answer for the ref and accepts it.
loaded, err := b.ix.load(context.Background(), PendingEntry{Key: "m.9", Value: Pending{Seq: 9}, Forge: RevisionForm(pushed), Light: true})
if err != nil || loaded.Forge.Merge != head || loaded.Light {
t.Fatalf("load = %+v, %v, want the pushed message read at the head", loaded.Forge, err)
}
}