package gateway

import (
	"strings"
	"testing"

	"lingniu-vehicle-ingest/go/vehicle-gateway/internal/envelope"
	"lingniu-vehicle-ingest/go/vehicle-gateway/internal/metrics"
)

func TestRecordGatewayIdentityCacheStatus(t *testing.T) {
	registry := metrics.NewRegistry()
	recordGatewayIdentityCacheStatus(registry, envelope.ProtocolJT808, envelope.FrameEnvelope{
		Parsed: map[string]any{
			"identity": map[string]any{
				"resolved":     true,
				"cache_status": "stale",
			},
		},
	})

	got := registry.Render()
	want := `vehicle_gateway_identity_cache_total{cache_status="stale",protocol="JT808"} 1`
	if !strings.Contains(got, want) {
		t.Fatalf("metrics missing %q:\n%s", want, got)
	}
}
