conf/dotenv_test.go
juancwu c4ebd80669 Add reflective struct-tag config loader
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>
2026-04-27 20:35:51 +00:00

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")
}
}