feat(lns): align by-name aliases with label-aware lookups
This commit is contained in:
parent
82eeaa0f9b
commit
c9d1a9fdbb
2 changed files with 28 additions and 24 deletions
36
lns.go
36
lns.go
|
|
@ -135,23 +135,17 @@ func (s *Service) HasReserved(name any) bool {
|
|||
return ok
|
||||
}
|
||||
|
||||
// GetReservedByName looks up a reserved name using the raw catalog label.
|
||||
// GetReservedByName is an alias for GetReservedName.
|
||||
//
|
||||
// This mirrors the covenant package helper without requiring .lthn
|
||||
// canonicalisation first.
|
||||
// This keeps the service-level name lookup helpers consistent: callers can
|
||||
// pass either a raw catalog label or a canonical `.lthn` name.
|
||||
func (s *Service) GetReservedByName(name any) (covenant.ReservedName, bool) {
|
||||
label, ok := catalogLabel(name)
|
||||
if !ok {
|
||||
return covenant.ReservedName{}, false
|
||||
}
|
||||
|
||||
return covenant.GetReservedName(label)
|
||||
return s.GetReservedName(name)
|
||||
}
|
||||
|
||||
// HasReservedByName reports whether the raw catalog label is reserved.
|
||||
// HasReservedByName is an alias for HasReservedName.
|
||||
func (s *Service) HasReservedByName(name any) bool {
|
||||
_, ok := s.GetReservedByName(name)
|
||||
return ok
|
||||
return s.HasReservedName(name)
|
||||
}
|
||||
|
||||
// HasReservedName reports whether a reserved name exists using the raw
|
||||
|
|
@ -225,23 +219,17 @@ func (s *Service) HasLocked(name any) bool {
|
|||
return ok
|
||||
}
|
||||
|
||||
// GetLockedByName looks up a locked name using the raw catalog label.
|
||||
// GetLockedByName is an alias for GetLockedName.
|
||||
//
|
||||
// This mirrors the covenant package helper without requiring .lthn
|
||||
// canonicalisation first.
|
||||
// This keeps the service-level name lookup helpers consistent: callers can
|
||||
// pass either a raw catalog label or a canonical `.lthn` name.
|
||||
func (s *Service) GetLockedByName(name any) (covenant.LockedName, bool) {
|
||||
label, ok := catalogLabel(name)
|
||||
if !ok {
|
||||
return covenant.LockedName{}, false
|
||||
}
|
||||
|
||||
return covenant.GetLockedName(label)
|
||||
return s.GetLockedName(name)
|
||||
}
|
||||
|
||||
// HasLockedByName reports whether the raw catalog label is locked.
|
||||
// HasLockedByName is an alias for HasLockedName.
|
||||
func (s *Service) HasLockedByName(name any) bool {
|
||||
_, ok := s.GetLockedByName(name)
|
||||
return ok
|
||||
return s.HasLockedName(name)
|
||||
}
|
||||
|
||||
// HasLockedName reports whether a locked name exists using the raw catalog
|
||||
|
|
|
|||
16
lns_test.go
16
lns_test.go
|
|
@ -183,6 +183,10 @@ func TestServiceGetReservedByName(t *testing.T) {
|
|||
t.Fatal("GetReservedByName([]byte) should find the reserved reference entry")
|
||||
}
|
||||
|
||||
if _, ok := svc.GetReservedByName("RESERVED.lthn"); !ok {
|
||||
t.Fatal("GetReservedByName should also accept canonical reserved names")
|
||||
}
|
||||
|
||||
if _, ok := svc.GetReservedByName(123); ok {
|
||||
t.Fatal("GetReservedByName should reject unsupported input types")
|
||||
}
|
||||
|
|
@ -199,6 +203,10 @@ func TestServiceHasReservedByName(t *testing.T) {
|
|||
t.Fatal("HasReservedByName([]byte) should report reserved catalog labels")
|
||||
}
|
||||
|
||||
if !svc.HasReservedByName("reserved.lthn") {
|
||||
t.Fatal("HasReservedByName should report canonical reserved names")
|
||||
}
|
||||
|
||||
if svc.HasReservedByName("not-reserved") {
|
||||
t.Fatal("HasReservedByName should return false for unknown labels")
|
||||
}
|
||||
|
|
@ -355,6 +363,10 @@ func TestServiceGetLockedByName(t *testing.T) {
|
|||
t.Fatal("GetLockedByName([]byte) should find the locked reference entry")
|
||||
}
|
||||
|
||||
if _, ok := svc.GetLockedByName("NEC.lthn"); !ok {
|
||||
t.Fatal("GetLockedByName should also accept canonical locked names")
|
||||
}
|
||||
|
||||
if _, ok := svc.GetLockedByName(123); ok {
|
||||
t.Fatal("GetLockedByName should reject unsupported input types")
|
||||
}
|
||||
|
|
@ -371,6 +383,10 @@ func TestServiceHasLockedByName(t *testing.T) {
|
|||
t.Fatal("HasLockedByName([]byte) should report locked catalog labels")
|
||||
}
|
||||
|
||||
if !svc.HasLockedByName("nec.lthn") {
|
||||
t.Fatal("HasLockedByName should report canonical locked names")
|
||||
}
|
||||
|
||||
if svc.HasLockedByName("not-locked") {
|
||||
t.Fatal("HasLockedByName should return false for unknown labels")
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue