1package setting
2
3import (
4	"os"
5	"testing"
6
7	"github.com/stretchr/testify/require"
8)
9
10func TestDynamicSettingsSupport_Override(t *testing.T) {
11	cfg := NewCfg()
12	envKey := "GF_FOO_BAR"
13	sectionName := "foo"
14	keyName := "bar"
15	expected := "dynamic value"
16
17	err := os.Setenv(envKey, expected)
18	require.NoError(t, err)
19	defer func() {
20		err := os.Unsetenv(envKey)
21		require.NoError(t, err)
22	}()
23
24	value := cfg.SectionWithEnvOverrides(sectionName).Key(keyName).MustString("default value")
25	require.Equal(t, expected, value)
26}
27
28func TestDynamicSettingsSupport_NoOverride(t *testing.T) {
29	cfg := NewCfg()
30
31	sectionName := "foo"
32	keyName := "bar"
33	expected := "default value"
34
35	_, err := cfg.Raw.Section(sectionName).NewKey(keyName, expected)
36	require.NoError(t, err)
37	value := cfg.SectionWithEnvOverrides(sectionName).Key(keyName).String()
38	require.Equal(t, expected, value)
39}
40