fix(lns): fall back to canonical catalogs
This commit is contained in:
parent
28d8907c17
commit
321d88b3a6
2 changed files with 66 additions and 4 deletions
24
lns.go
24
lns.go
|
|
@ -2435,7 +2435,11 @@ func (s *Service) reservedCatalog() *covenant.ReservedCatalog {
|
|||
return s.reservedCatalogOverride
|
||||
}
|
||||
|
||||
return Reserved
|
||||
if Reserved != nil {
|
||||
return Reserved
|
||||
}
|
||||
|
||||
return covenant.DefaultReservedCatalog()
|
||||
}
|
||||
|
||||
// lockedCatalog returns the package-backed locked-name catalog.
|
||||
|
|
@ -2444,7 +2448,11 @@ func (s *Service) lockedCatalog() *covenant.LockedCatalog {
|
|||
return s.lockedCatalogOverride
|
||||
}
|
||||
|
||||
return Locked
|
||||
if Locked != nil {
|
||||
return Locked
|
||||
}
|
||||
|
||||
return covenant.DefaultLockedCatalog()
|
||||
}
|
||||
|
||||
// GetCore is an alias for Core.
|
||||
|
|
@ -2729,14 +2737,22 @@ var Locked = covenant.DefaultLockedCatalog()
|
|||
//
|
||||
// catalog := lns.ReservedCatalog()
|
||||
func ReservedCatalog() *covenant.ReservedCatalog {
|
||||
return Reserved
|
||||
if Reserved != nil {
|
||||
return Reserved
|
||||
}
|
||||
|
||||
return covenant.DefaultReservedCatalog()
|
||||
}
|
||||
|
||||
// LockedCatalog exposes the locked-name catalog used by the package.
|
||||
//
|
||||
// catalog := lns.LockedCatalog()
|
||||
func LockedCatalog() *covenant.LockedCatalog {
|
||||
return Locked
|
||||
if Locked != nil {
|
||||
return Locked
|
||||
}
|
||||
|
||||
return covenant.DefaultLockedCatalog()
|
||||
}
|
||||
|
||||
// ReservedSize reports the number of reserved-name entries available to the package.
|
||||
|
|
|
|||
|
|
@ -404,6 +404,52 @@ func TestPackageDefaultCatalogsIgnoreOverrides(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestPackageCatalogFallbacksWhenNil(t *testing.T) {
|
||||
origReserved := Reserved
|
||||
origLocked := Locked
|
||||
defer func() {
|
||||
Reserved = origReserved
|
||||
Locked = origLocked
|
||||
}()
|
||||
|
||||
Reserved = nil
|
||||
Locked = nil
|
||||
|
||||
if ReservedCatalog() == nil {
|
||||
t.Fatal("ReservedCatalog should fall back to the canonical catalog when nil")
|
||||
}
|
||||
|
||||
if LockedCatalog() == nil {
|
||||
t.Fatal("LockedCatalog should fall back to the canonical catalog when nil")
|
||||
}
|
||||
|
||||
if _, ok := GetReservedName("RESERVED"); !ok {
|
||||
t.Fatal("GetReservedName should keep working when Reserved is nil")
|
||||
}
|
||||
|
||||
if _, ok := GetLockedName("NEC"); !ok {
|
||||
t.Fatal("GetLockedName should keep working when Locked is nil")
|
||||
}
|
||||
|
||||
svc := NewService(nil)
|
||||
|
||||
if svc.ReservedCatalog() == nil {
|
||||
t.Fatal("service ReservedCatalog should fall back to the canonical catalog when nil")
|
||||
}
|
||||
|
||||
if svc.LockedCatalog() == nil {
|
||||
t.Fatal("service LockedCatalog should fall back to the canonical catalog when nil")
|
||||
}
|
||||
|
||||
if _, ok := svc.GetReservedName("RESERVED"); !ok {
|
||||
t.Fatal("service GetReservedName should keep working when Reserved is nil")
|
||||
}
|
||||
|
||||
if _, ok := svc.GetLockedName("NEC"); !ok {
|
||||
t.Fatal("service GetLockedName should keep working when Locked is nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestLookupCatalogNamePreservesDottedLabels(t *testing.T) {
|
||||
hash := primitives.Hash(sha3.Sum256([]byte("foo.bar")))
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue