package event

import (
	"strings"
	"testing"

	"github.com/stretchr/testify/assert"
)

func TestNormalizeGroupKey(t *testing.T) {
	short := `{}/{alertname="TiKVDown"}:{cluster="c1"}`
	assert.Equal(t, short, NormalizeGroupKey(short))

	long := `{}/{alertname="X"}:` + strings.Repeat("label=value,", 100)
	got := NormalizeGroupKey(long)
	assert.LessOrEqual(t, len(got), 255)
	assert.Contains(t, got, "#")

	// Deterministic: same input → same key (grouping preserved).
	assert.Equal(t, got, NormalizeGroupKey(long))

	// Different long keys with same prefix must not collide.
	other := long + "x"
	assert.NotEqual(t, got, NormalizeGroupKey(other))
}
