(t *testing.T)
| 2378 | } |
| 2379 | |
| 2380 | func newViperWithSymlinkedConfigFile(t *testing.T) (*Viper, string, string) { |
| 2381 | watchDir := t.TempDir() |
| 2382 | dataDir1 := path.Join(watchDir, "data1") |
| 2383 | err := os.Mkdir(dataDir1, 0o777) |
| 2384 | require.NoError(t, err) |
| 2385 | realConfigFile := path.Join(dataDir1, "config.yaml") |
| 2386 | t.Logf("Real config file location: %s\n", realConfigFile) |
| 2387 | err = os.WriteFile(realConfigFile, []byte("foo: bar\n"), 0o640) |
| 2388 | require.NoError(t, err) |
| 2389 | // now, symlink the tm `data1` dir to `data` in the baseDir |
| 2390 | os.Symlink(dataDir1, path.Join(watchDir, "data")) |
| 2391 | // and link the `<watchdir>/datadir1/config.yaml` to `<watchdir>/config.yaml` |
| 2392 | configFile := path.Join(watchDir, "config.yaml") |
| 2393 | os.Symlink(path.Join(watchDir, "data", "config.yaml"), configFile) |
| 2394 | t.Logf("Config file location: %s\n", path.Join(watchDir, "config.yaml")) |
| 2395 | // init Viper |
| 2396 | v := New() |
| 2397 | v.SetConfigFile(configFile) |
| 2398 | err = v.ReadInConfig() |
| 2399 | require.NoError(t, err) |
| 2400 | require.Equal(t, "bar", v.Get("foo")) |
| 2401 | return v, watchDir, configFile |
| 2402 | } |
| 2403 | |
| 2404 | func TestWatchFile(t *testing.T) { |
| 2405 | if runtime.GOOS == "linux" { |
no test coverage detected