Implements conf.Load to populate tagged structs from a chain of Sources (env, .env, YAML/JSON/TOML, custom). Supports default values, slice separators, nested structs, pointer fields, and a Validator hook. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
35 lines
621 B
Go
35 lines
621 B
Go
package conf
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestDotEnvReader(t *testing.T) {
|
|
in := `# comment
|
|
FOO=bar
|
|
export QUOTED="hello\nworld"
|
|
SINGLE='ab cd'
|
|
INLINE=plain # trailing
|
|
EMPTY=
|
|
`
|
|
src, err := DotEnvReader(strings.NewReader(in))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
cases := map[string]string{
|
|
"FOO": "bar",
|
|
"QUOTED": "hello\nworld",
|
|
"SINGLE": "ab cd",
|
|
"INLINE": "plain",
|
|
}
|
|
for k, want := range cases {
|
|
got, ok := src.Lookup(k)
|
|
if !ok || got != want {
|
|
t.Errorf("%s = %q ok=%v, want %q", k, got, ok, want)
|
|
}
|
|
}
|
|
if _, ok := src.Lookup("EMPTY"); ok {
|
|
t.Errorf("EMPTY should be absent")
|
|
}
|
|
}
|