Add semantic service snapshot alias

This commit is contained in:
Virgil 2026-04-04 02:55:03 +00:00
parent d1e884f2e2
commit 612cf06c06
2 changed files with 30 additions and 3 deletions

View file

@ -1169,11 +1169,11 @@ func (service *Service) Health() HealthResult {
}
}
// Describe returns a structured snapshot that is easier to inspect than String().
// Snapshot returns a structured view of the service state.
//
// snapshot := service.Describe()
// snapshot := service.Snapshot()
// fmt.Printf("%+v\n", snapshot)
func (service *Service) Describe() ServiceDescription {
func (service *Service) Snapshot() ServiceDescription {
if service == nil {
return ServiceDescription{
Status: "not_ready",
@ -1211,6 +1211,14 @@ func (service *Service) Describe() ServiceDescription {
}
}
// Describe is the compatibility alias for Snapshot.
//
// snapshot := service.Describe()
// fmt.Printf("%+v\n", snapshot)
func (service *Service) Describe() ServiceDescription {
return service.Snapshot()
}
// ZoneApex returns the computed apex for the current record set.
//
// apex := service.ZoneApex()

View file

@ -686,6 +686,25 @@ func TestServiceDescribeReturnsSemanticSnapshot(t *testing.T) {
}
}
func TestServiceSnapshotMatchesDescribe(t *testing.T) {
service := NewService(ServiceOptions{
Records: map[string]NameRecords{
"gateway.charon.lthn": {
A: []string{"10.10.10.10"},
},
},
DNSPort: 1053,
HTTPPort: 5555,
})
snapshot := service.Snapshot()
description := service.Describe()
if snapshot != description {
t.Fatalf("expected Snapshot to match Describe, got %#v and %#v", snapshot, description)
}
}
func TestServiceServeHTTPHealthReturnsJSON(t *testing.T) {
service := NewService(ServiceOptions{
Records: map[string]NameRecords{