koanf.Unmarshal doesn't work when loaded with env provider
nomikz opened this issue · comments
nomikz commented
Description:
koanf.Unmarshal doesn't work when loaded by env provider
Is this expected behaviour?
Test: this test has no dependencies like files, envrionemnt variables.
package config
import (
"os"
"testing"
"github.com/knadh/koanf/providers/env"
koanf "github.com/knadh/koanf/v2"
"github.com/stretchr/testify/require"
)
type Conf struct {
Key string `koanf:"key"`
}
func TestTest(t *testing.T) {
k := koanf.New("")
// Set env variable
require.NoError(t, os.Setenv("key", "value"))
// Load environment variables
err := k.Load(env.Provider("", "", nil), nil)
require.NoError(t, err)
// This passes successfully
require.Equal(t, "value", k.String("key"))
var c Conf
err = k.Unmarshal("", &c)
require.NoError(t, err)
// Here, it is expected that value is unmarshalled
require.Equal(t, "value", c.Key)
}
Expected behavior
Value must have been successfully unmarshalled into a struct.
OS: macOS Sonama Version 14.3.1
Koanf Version: v2.1.0
david may commented
in case you didn't know, it works when you provide a delimiter: env.Provider("", ".", nil)