package console import ( "encoding/json" "sync" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog" "github.com/novox/mesh-tools/node-tools/internal/bus" mt "github.com/novox/mesh-tools/node-tools/internal/meshtest" ) // busSource is a Source over a bus connection's own states, which a test's fixture mesh fills: the console's tests stand a // membership that reads the four states beside it, where the tool runner itself holds first views (firstview.Views). type busSource struct{ conn *bus.Conn } func (b busSource) State(name string) (map[string][]byte, error) { var mu sync.Mutex keys := map[string][]byte{} stop, err := b.conn.StateWatch(b.conn.Credential().Module, name, "", func(c bus.StateChange) error { if c.Current && c.Op == "put" { mu.Lock() keys[c.Key] = c.Value mu.Unlock() } return nil }) if err != nil { return nil, err } stop() mu.Lock() defer mu.Unlock() return keys, nil } func (b busSource) Entry(name, key string) ([]byte, error) { entry, err := b.conn.StateGet(b.conn.Credential().Module, name, key) if err != nil || entry == nil { return nil, err } return entry.Value, nil } // Modules reads the test bed's entries of the catalog half (meshtest.ModulesRead), as the tool runner's first views hold them. func (b busSource) Modules() (map[string]meshcatalog.CatalogEntry, error) { raw, err := b.State(mt.ModulesRead) if err != nil { return nil, err } out := map[string]meshcatalog.CatalogEntry{} for module, value := range raw { var e meshcatalog.CatalogEntry if err := json.Unmarshal(value, &e); err != nil { return nil, err } out[module] = e } return out, nil }