Build configuration in tests without touching the filesystem. Use source.NewMap to provide values from a plain Go map, and synthratest.Config to get a ready-to-use *synthra.Config that fails the test on construction errors.
cd examples/testing && go test -vgo run . prints a short pointer to the tests -- the real content is in main_test.go.
cfg := synthratest.Config(t,
synthra.WithSource(source.NewMap(map[string]any{
"server": map[string]any{"port": 8080, "host": "127.0.0.1"},
})),
)
require.NoError(t, cfg.Load(t.Context()))
port, err := cfg.Int("server.port")- No files in tests --
source.NewMapkeeps tests fast, deterministic, and free from path issues. - Test helper --
synthratest.Configcallst.Fatalon error so your test stays clean. - Same API -- the config object you get back works exactly like a production one.