package metrics

import (
	"testing"

	"github.com/prometheus/client_golang/prometheus"
	"github.com/prometheus/client_golang/prometheus/testutil"
	"github.com/stretchr/testify/assert"
	"github.com/tidbcloud/shared-provider/pkg/types"
)

func TestGaugeVec(t *testing.T) {
	aaaLabel1 := prometheus.Labels{
		"provider_type": types.ProviderTypeAWSSharedTier,
		"namespace":     "aaa",
		"network":       "aaa",
		"region":        "us-west-1",
		"kubernetes":    "xxx",
		"phase":         "test",
	}

	aaaLabel2 := prometheus.Labels{
		"provider_type": types.ProviderTypeAWSSharedTier,
		"namespace":     "aaa",
		"network":       "aaa",
		"region":        "us-west-2",
		"kubernetes":    "xxx",
		"phase":         "test",
	}

	bbbLabel1 := prometheus.Labels{
		"provider_type": types.ProviderTypeAWSSharedTier,
		"namespace":     "bbb",
		"network":       "bbb",
		"region":        "us-west-2",
		"kubernetes":    "xxx",
		"phase":         "test",
	}

	NetworkPhase.Set(aaaLabel1, 1)
	assert.Equal(t, 1, testutil.CollectAndCount(NetworkPhase))
	NetworkPhase.Set(bbbLabel1, 1)
	assert.Equal(t, 2, testutil.CollectAndCount(NetworkPhase))
	NetworkPhase.Set(aaaLabel2, 1)
	assert.Equal(t, 2, testutil.CollectAndCount(NetworkPhase))

	aaaKeyLabel := prometheus.Labels{
		"namespace": "aaa",
		"network":   "aaa",
	}
	bbbKeyLabel := prometheus.Labels{
		"namespace": "bbb",
		"network":   "bbb",
	}

	NetworkPhase.Delete(aaaKeyLabel)
	assert.Equal(t, 1, testutil.CollectAndCount(NetworkPhase))
	NetworkPhase.Delete(bbbKeyLabel)
	assert.Equal(t, 0, testutil.CollectAndCount(NetworkPhase))
}
