package configs

import (
	"io/fs"
	"os"
	"testing"

	"github.com/stretchr/testify/assert"
	"gopkg.in/yaml.v3"
)

func TestLoadOverlayAlertRuleCacheConfig(t *testing.T) {
	t.Run("normal", func(t *testing.T) {
		config := make(map[string]interface{})

		config["expireTime"] = "10m"
		config["maxItems"] = 1000
		config["maxAlertRulesPerCluster"] = 200
		config["enabled"] = true
		config["sleepTime"] = "1800s"
		config["maxDeletionPerCycle"] = 10

		content, err := yaml.Marshal(config)
		assert.NoError(t, err)
		path := "alertrulecacheconfig.yaml"
		os.WriteFile(path, content, fs.ModePerm)
		defer os.Remove(path)

		result := LoadOverlayAlertRuleCacheConfig(path)
		assert.NotEmpty(t, result)

	})
	t.Run("invalid file", func(t *testing.T) {
		assert.Panics(t, func() {
			LoadOverlayAlertRuleCacheConfig("invalid")
		})
	})
}
