diff options
| -rw-r--r-- | internal/rpn/metric_parse.go | 2 | ||||
| -rw-r--r-- | internal/rpn/metric_registry.go | 11 | ||||
| -rw-r--r-- | internal/rpn/operations.go | 2 | ||||
| -rw-r--r-- | internal/rpn/operations_interfaces.go | 2 |
4 files changed, 14 insertions, 3 deletions
diff --git a/internal/rpn/metric_parse.go b/internal/rpn/metric_parse.go index 28c08de..e7a4611 100644 --- a/internal/rpn/metric_parse.go +++ b/internal/rpn/metric_parse.go @@ -10,7 +10,7 @@ import "strconv" // The metric suffix is looked up in the given registry (exact, alias, then case-insensitive). // Returns (num, metric, true) if successful, or (0, nil, false) if the token // does not contain a number+metric combination. -func parseNumberWithMetric(token string, reg *MetricRegistry) (float64, *Metric, bool) { +func parseNumberWithMetric(token string, reg MetricReader) (float64, *Metric, bool) { if len(token) == 0 { return 0, nil, false } diff --git a/internal/rpn/metric_registry.go b/internal/rpn/metric_registry.go index 2c89b11..a221e56 100644 --- a/internal/rpn/metric_registry.go +++ b/internal/rpn/metric_registry.go @@ -17,6 +17,17 @@ type MetricRegistry struct { exactMatchNames map[string]bool // names that must match exactly (no case-insensitive fallback) } +// MetricReader defines the read-only operations on a metric registry. +// This interface allows tests to mock the registry without depending on the +// concrete *MetricRegistry type. +type MetricReader interface { + Find(name string) (*Metric, bool) + FindCaseInsensitive(name string) (*Metric, bool) + FindWithAliases(name string) (*Metric, bool) + List() []*Metric + ListByCategory(cat Category) []*Metric +} + // Global registry instance. var defaultRegistry *MetricRegistry var registryOnce sync.Once diff --git a/internal/rpn/operations.go b/internal/rpn/operations.go index 832ac77..f79457c 100644 --- a/internal/rpn/operations.go +++ b/internal/rpn/operations.go @@ -90,6 +90,6 @@ func (o *Operations) SetPrefixMode(mode PrefixMode) { } // MetricRegistry returns the metric registry used by this Operations instance. -func (o *Operations) MetricRegistry() *MetricRegistry { +func (o *Operations) MetricRegistry() MetricReader { return o.metricRegistry } diff --git a/internal/rpn/operations_interfaces.go b/internal/rpn/operations_interfaces.go index 784ac76..8ad80ed 100644 --- a/internal/rpn/operations_interfaces.go +++ b/internal/rpn/operations_interfaces.go @@ -87,7 +87,7 @@ type ModeController interface { // MetricCommander defines the interface for metric query commands. type MetricCommander interface { - MetricRegistry() *MetricRegistry + MetricRegistry() MetricReader MetricShow(stack *Stack) (string, error) MetricList(stack *Stack) (string, error) MetricCategory(stack *Stack, categoryName string) (string, error) |
