feat(lns): expose service-level catalog lookup helpers
Add Service LookupCatalogName and GetLookupCatalogName wrappers and tests to ensure dotted-label catalog resolution remains preserved at service scope. Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
b66ae9bf29
commit
90f472a5f8
2 changed files with 63 additions and 0 deletions
23
lns.go
23
lns.go
|
|
@ -210,6 +210,29 @@ func lookupCatalogName[T any](
|
|||
return LookupCatalogName(name, byLabel, byHash)
|
||||
}
|
||||
|
||||
// LookupCatalogName resolves a raw or canonical catalog label with service-scoped
|
||||
// dispatch semantics that match the package-level helper.
|
||||
//
|
||||
// The helper first checks the raw label path, then falls back to canonical
|
||||
//
|
||||
// name hashing and hash callback resolution.
|
||||
func (s *Service) LookupCatalogName(
|
||||
name any,
|
||||
byLabel func(string) (any, bool),
|
||||
byHash func(primitives.Hash) (any, bool),
|
||||
) (any, bool) {
|
||||
return LookupCatalogName(name, byLabel, byHash)
|
||||
}
|
||||
|
||||
// GetLookupCatalogName is an alias for LookupCatalogName.
|
||||
func (s *Service) GetLookupCatalogName(
|
||||
name any,
|
||||
byLabel func(string) (any, bool),
|
||||
byHash func(primitives.Hash) (any, bool),
|
||||
) (any, bool) {
|
||||
return s.LookupCatalogName(name, byLabel, byHash)
|
||||
}
|
||||
|
||||
// Resolve returns the canonical hash for a validated .lthn name.
|
||||
//
|
||||
// This is the package-level convenience wrapper around Service.Resolve.
|
||||
|
|
|
|||
|
|
@ -308,6 +308,46 @@ func TestLookupCatalogNamePreservesDottedLabels(t *testing.T) {
|
|||
if !ok || got != "hash" {
|
||||
t.Fatalf("GetLookupCatalogName should alias LookupCatalogName, got %q ok=%v", got, ok)
|
||||
}
|
||||
|
||||
svc := NewService(nil)
|
||||
|
||||
gotAny, ok := svc.LookupCatalogName(
|
||||
"foo.bar",
|
||||
func(name string) (any, bool) {
|
||||
item, ok := byLabel[name]
|
||||
return any(item), ok
|
||||
},
|
||||
func(name primitives.Hash) (any, bool) {
|
||||
item, ok := byHash[name]
|
||||
return any(item), ok
|
||||
},
|
||||
)
|
||||
if !ok {
|
||||
t.Fatalf("svc.LookupCatalogName should resolve dotted raw labels, got ok=%v", ok)
|
||||
}
|
||||
gotStr, ok := gotAny.(string)
|
||||
if !ok || gotStr != "label" {
|
||||
t.Fatalf("svc.LookupCatalogName should resolve dotted raw labels, got %v ok=%v", gotAny, ok)
|
||||
}
|
||||
|
||||
gotAny, ok = svc.GetLookupCatalogName(
|
||||
"FOO.BAR.LTHN",
|
||||
func(name string) (any, bool) {
|
||||
item, ok := byLabel[name]
|
||||
return any(item), ok
|
||||
},
|
||||
func(name primitives.Hash) (any, bool) {
|
||||
item, ok := byHash[name]
|
||||
return any(item), ok
|
||||
},
|
||||
)
|
||||
if !ok {
|
||||
t.Fatalf("svc.GetLookupCatalogName should alias svc.LookupCatalogName, got ok=%v", ok)
|
||||
}
|
||||
gotStr, ok = gotAny.(string)
|
||||
if !ok || gotStr != "hash" {
|
||||
t.Fatalf("svc.GetLookupCatalogName should alias svc.LookupCatalogName, got %v ok=%v", gotAny, ok)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPackageTypeTables(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue