45 lines
1.5 KiB
Go
45 lines
1.5 KiB
Go
package index
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"errors"
|
|
"testing"
|
|
"time"
|
|
|
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
|
)
|
|
|
|
// Design 47 G A-370: the verb registrations answers from the state at once; it never asks the indexer (whose take-in may be
|
|
// running), but for a module's history, which the indexer reads from its stream.
|
|
func TestTheRegistrationsVerbIsAnsweredFromItsStateNotAskedOfTheIndexer(t *testing.T) {
|
|
store := MemoryStore()
|
|
data, _ := json.Marshal(meshcatalog.Registration{Module: "a"})
|
|
if err := store.Create(context.Background(), RegistrationKey("a"), data); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
asked := 0
|
|
ask := func(string, []byte) (TakeInAsk, error) {
|
|
asked++
|
|
return TakeInAsk{}, errors.New("the take-in is still running")
|
|
}
|
|
var tool func(map[string]any) (any, error)
|
|
for _, tl := range RegistrationTools(store, MemoryStore(), ask, time.Now, nil) {
|
|
if tl.Name == meshcatalog.Seat+"."+meshcatalog.VerbRegistrations {
|
|
tool = tl.Run
|
|
}
|
|
}
|
|
for _, args := range []map[string]any{{}, {"module": "a"}} {
|
|
got, err := tool(args)
|
|
if err != nil || len(got.(meshcatalog.RegistrationsAnswer).Registrations) != 1 {
|
|
t.Errorf("registrations %v = %+v, %v, want the one registration", args, got, err)
|
|
}
|
|
}
|
|
if asked != 0 {
|
|
t.Errorf("the indexer was asked %d times for a read of the state", asked)
|
|
}
|
|
if _, err := tool(map[string]any{"module": "a", "history": true}); err == nil || asked != 1 {
|
|
t.Errorf("a history is asked of the indexer: err %v, asked %d", err, asked)
|
|
}
|
|
}
|