|
| 1 | +package config_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "os" |
| 5 | + "path/filepath" |
| 6 | + "runtime" |
| 7 | + |
| 8 | + . "github.com/onsi/ginkgo/v2" |
| 9 | + . "github.com/onsi/gomega" |
| 10 | + |
| 11 | + "github.com/vllm-project/semantic-router/semantic-router/pkg/config" |
| 12 | +) |
| 13 | + |
| 14 | +var _ = Describe("ParseConfigFile and ReplaceGlobalConfig", func() { |
| 15 | + var tempDir string |
| 16 | + |
| 17 | + BeforeEach(func() { |
| 18 | + var err error |
| 19 | + tempDir, err = os.MkdirTemp("", "config_parse_test") |
| 20 | + Expect(err).NotTo(HaveOccurred()) |
| 21 | + }) |
| 22 | + |
| 23 | + AfterEach(func() { |
| 24 | + os.RemoveAll(tempDir) |
| 25 | + config.ResetConfig() |
| 26 | + }) |
| 27 | + |
| 28 | + It("should parse configuration via symlink path", func() { |
| 29 | + if runtime.GOOS == "windows" { |
| 30 | + Skip("symlink test is skipped on Windows") |
| 31 | + } |
| 32 | + |
| 33 | + // Create real config target |
| 34 | + target := filepath.Join(tempDir, "real-config.yaml") |
| 35 | + content := []byte("default_model: test-model\n") |
| 36 | + Expect(os.WriteFile(target, content, 0o644)).To(Succeed()) |
| 37 | + |
| 38 | + // Create symlink pointing to target |
| 39 | + link := filepath.Join(tempDir, "link-config.yaml") |
| 40 | + Expect(os.Symlink(target, link)).To(Succeed()) |
| 41 | + |
| 42 | + cfg, err := config.ParseConfigFile(link) |
| 43 | + Expect(err).NotTo(HaveOccurred()) |
| 44 | + Expect(cfg).NotTo(BeNil()) |
| 45 | + Expect(cfg.DefaultModel).To(Equal("test-model")) |
| 46 | + }) |
| 47 | + |
| 48 | + It("should return error when file does not exist", func() { |
| 49 | + _, err := config.ParseConfigFile(filepath.Join(tempDir, "no-such.yaml")) |
| 50 | + Expect(err).To(HaveOccurred()) |
| 51 | + Expect(err.Error()).To(ContainSubstring("failed to read config file")) |
| 52 | + }) |
| 53 | + |
| 54 | + It("should replace global config and reflect via GetConfig", func() { |
| 55 | + // new config instance |
| 56 | + newCfg := &config.RouterConfig{DefaultModel: "new-default"} |
| 57 | + config.ReplaceGlobalConfig(newCfg) |
| 58 | + got := config.GetConfig() |
| 59 | + Expect(got).To(Equal(newCfg)) |
| 60 | + Expect(got.DefaultModel).To(Equal("new-default")) |
| 61 | + }) |
| 62 | +}) |
0 commit comments