Files
config/provider/env/provider_test.go
andrey deca96cf6b
All checks were successful
Go Action / goaction (pull_request) Successful in 1m17s
add dump refereence env provider
2026-01-03 14:51:00 +03:00

61 lines
1.3 KiB
Go

package env_test
import (
"bytes"
"context"
"testing"
"gitoa.ru/go-4devs/config"
"gitoa.ru/go-4devs/config/definition/group"
"gitoa.ru/go-4devs/config/definition/option"
"gitoa.ru/go-4devs/config/definition/proto"
"gitoa.ru/go-4devs/config/provider/env"
"gitoa.ru/go-4devs/config/test"
"gitoa.ru/go-4devs/config/test/require"
)
func TestProvider(t *testing.T) {
t.Setenv("FDEVS_CONFIG_DSN", test.DSN)
t.Setenv("FDEVS_CONFIG_PORT", "8080")
provider := env.New("fdevs", "config")
read := []test.Read{
test.NewRead(test.DSN, "dsn"),
test.NewRead(8080, "port"),
}
test.Run(t, provider, read)
}
func TestProvider_DumpReference(t *testing.T) {
t.Parallel()
const expect = `# configure log.
# level.
FDEVS_CONFIG_LOG_LEVEL=info
# configure log service.
# level.
#FDEVS_CONFIG_LOG_{SERVICE}_LEVEL=
`
ctx := context.Background()
prov := env.New("fdevs", "config")
buf := bytes.NewBuffer(nil)
require.NoError(t, prov.DumpReference(ctx, buf, testOptions(t)))
require.Equal(t, buf.String(), expect)
}
func testOptions(t *testing.T) config.Options {
t.Helper()
return group.New("test", "test",
group.New("log", "configure log",
option.String("level", "level", option.Default("info")),
proto.New("service", "configure log service",
option.String("level", "level"),
),
),
)
}