package configs

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

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

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

		config["maxWorkers"] = 8
		config["maxJobs"] = 1000
		config["queryClusterLimit"] = 200
		config["failedRetryTimes"] = 3
		config["rotationInterval"] = "1800s"
		config["resyncPeriod"] = "30s"
		config["swtich"] = true

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

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

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