package connector_events

import (
	"testing"

	"github.com/prometheus/client_golang/prometheus"
)

func TestInitializeLiveQueueMetricsCreatesEveryFixedSeries(t *testing.T) {
	InitializeLiveQueueMetrics()

	families, err := prometheus.DefaultGatherer.Gather()
	if err != nil {
		t.Fatalf("gather metrics: %v", err)
	}

	want := map[string]map[string]bool{
		"nexuscrm_connector_event_queue_depth": {
			"pending":          false,
			"due":              false,
			"failed_due":       false,
			"failed_not_due":   false,
			"processing":       false,
			"stale_processing": false,
		},
		"nexuscrm_connector_event_queue_oldest_age_seconds": {
			"pending":    false,
			"due":        false,
			"failed_due": false,
			"processing": false,
		},
	}
	labelName := map[string]string{
		"nexuscrm_connector_event_queue_depth":              "state",
		"nexuscrm_connector_event_queue_oldest_age_seconds": "bucket",
	}
	for _, family := range families {
		series, ok := want[family.GetName()]
		if !ok {
			continue
		}
		for _, metric := range family.GetMetric() {
			for _, label := range metric.GetLabel() {
				if label.GetName() == labelName[family.GetName()] {
					if _, exists := series[label.GetValue()]; exists {
						series[label.GetValue()] = true
					}
				}
			}
		}
	}
	for family, series := range want {
		for label, found := range series {
			if !found {
				t.Errorf("%s{%s=%q} was not initialized", family, labelName[family], label)
			}
		}
	}
}
