38 lines
1.7 KiB
Go
38 lines
1.7 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"testing"
|
|
|
|
"github.com/novox/mesh-controller/internal/broker"
|
|
"github.com/novox/mesh-controller/internal/inventory"
|
|
"github.com/novox/mesh-controller/internal/link"
|
|
)
|
|
|
|
// 1211/AC1 to AC3: the controller keeps a merge announced by a module that claims the delivery seat, whatever its
|
|
// name, and takes no word from one that does not (novox/hq ADR 0437 §3). With no bus held, a word that passes the
|
|
// claim is held for the bus (ErrTryAgain); a word that does not is refused before the bus is asked.
|
|
func TestOnlyAModuleClaimingTheSeatIsTheDeliverysWordOnAMerge(t *testing.T) {
|
|
entries := []inventory.Entry{claimingTheSeat("mesh-delivery-gate"), namedOnly("gitea"), namedOnly("mesh-delivery")}
|
|
keeper := keepingDeliveryMerges{
|
|
js: func() *broker.JetStream { return nil },
|
|
catalog: func(context.Context) ([]inventory.Entry, error) { return entries, nil },
|
|
}
|
|
body := []byte(`{"owner":"novox","repo":"r","number":1,"head_sha":"abc","ask_id":"a","option":"approve"}`)
|
|
for emitter, passes := range map[string]bool{
|
|
"mesh-delivery-gate": true, // the claimant, under another name
|
|
"gitea": false, // claims no seat
|
|
"mesh-delivery": false, // named so, claiming no seat here
|
|
} {
|
|
err := keeper.KeepDeliveryMerge(context.Background(), emitter, body)
|
|
if passes != errors.Is(err, link.ErrTryAgain) || (!passes && !errors.Is(err, link.ErrNotTheDeliverysWord)) {
|
|
t.Errorf("%s: %v (passes the claim: %v)", emitter, err, passes)
|
|
}
|
|
}
|
|
entries = []inventory.Entry{claimingTheSeat("mesh-delivery")}
|
|
if err := keeper.KeepDeliveryMerge(context.Background(), "mesh-delivery", body); !errors.Is(err, link.ErrTryAgain) {
|
|
t.Errorf("today's module, claiming the seat: %v", err)
|
|
}
|
|
}
|