package processor

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

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

func TestNewConfig(t *testing.T) {
	t.Run("normal", func(t *testing.T) {
		g := NewGomegaWithT(t)
		config := Config{
			Region:      "us-west-2",
			Bucket:      "test-bucket",
			EvaBucket:   "test-eva-bucket",
			DataSources: []string{"ds1", "ds2"},
			Version:     "v1",
		}
		content, err := yaml.Marshal(config)
		assert.NoError(t, err)
		path := "test_config.yaml"
		os.WriteFile(path, content, fs.ModePerm)
		defer os.Remove(path)
		g.Expect(NewConfig(path)).Should(Equal(config))
	})
	t.Run("invalid file", func(t *testing.T) {
		assert.Panics(t, func() {
			NewConfig("invalid")
		})
	})
}
