package configs

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

	"github.com/stretchr/testify/assert"
	"github.com/tidbcloud/observability/pkg/common/structs"
	"gopkg.in/yaml.v3"
)

func TestLoadVMConfig(t *testing.T) {
	t.Run("normal", func(t *testing.T) {
		config := []structs.VictoriaMetricsCluster{
			{VMClusterName: "cluster0"},
		}

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

		result := LoadVMConfig(path)
		assert.NotEmpty(t, result)
		assert.Equal(t, "cluster0", result[0].VMClusterName)

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