MCPcopy
hub / github.com/spf13/viper / newViperWithSymlinkedConfigFile

Function newViperWithSymlinkedConfigFile

viper_test.go:2380–2402  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2378}
2379
2380func 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
2404func TestWatchFile(t *testing.T) {
2405 if runtime.GOOS == "linux" {

Callers 1

TestWatchFileFunction · 0.85

Calls 4

NewFunction · 0.85
SetConfigFileMethod · 0.80
ReadInConfigMethod · 0.80
GetMethod · 0.65

Tested by

no test coverage detected