package config import ( "os" "path/filepath" "testing" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" ) func TestConfig(t *testing.T) { RegisterFailHandler(Fail) RunSpecs(t, "Config Suite") } var _ = Describe("Config", func() { var originalEnv string BeforeEach(func() { // Save the original GO_ENV value originalEnv = os.Getenv("GO_ENV") }) AfterEach(func() { // Restore the original GO_ENV value os.Setenv("GO_ENV", originalEnv) }) // Helper function to create temporary TOML files in the "configs" directory createTempConfigFile := func(env, content string) string { dir := "configs" err := os.MkdirAll(dir, 0755) Expect(err).NotTo(HaveOccurred(), "failed to create config directory") filename := filepath.Join(dir, "config."+env+".toml") tmpfile, err := os.Create(filename) Expect(err).NotTo(HaveOccurred(), "failed to create temp config file") _, err = tmpfile.Write([]byte(content)) Expect(err).NotTo(HaveOccurred(), "failed to write to temp config file") err = tmpfile.Close() Expect(err).NotTo(HaveOccurred(), "failed to close temp config file") return filename } Context("Loading and validating a valid TOML file", func() { It("should load and validate the configuration correctly", func() { content := ` [nats] client = "test-client" url = "nats://localhost:4222" cluster = "test-cluster" [subscription] topic = "example-topic" queue_group = "example-group" [timeouts] server_timeout = "30s" reconnect_wait = "10s" close_timeout = "10s" ack_wait_timeout = "5s" [[body]] name = "FPL" [[body.patterns]] pattern = "^\\((?P[A-Z]{3})\\-(?P[A-Z]+\\d+)\\-(?P[A-Z]{2})(?:.*\\s*)?\\-(?P[A-Z]+\\d+/?[A-Z]?)\\s*\\-(?P.*)\\s*\\-(?P[A-Z]{4})(?P\\d{4})\\s*\\-(?P[A-Z]+\\d+)(?P[A-Z0-9]+)\\s(?P.*)\\s*\\-(?P[A-Z]{4})(?P\\d{4})\\s(?P[A-Z]{4})\\s*\\-(?PPBN\\/[A-Z0-9]+)\\s(?P