func TestUnexportedField(t *testing.T) { var conf struct { name string } os.Setenv("NAME", "foobar") err := envconfig.Init(&conf) require.Equal(t, envconfig.ErrUnexportedField, err) err = envconfig.InitWithOptions(&conf, envconfig.Options{AllowUnexported: true}) require.Equal(t, nil, err) }
func TestLeaveNil(t *testing.T) { var conf struct { MySQL *struct { Name string } } err := envconfig.InitWithOptions(&conf, envconfig.Options{ AllOptional: true, LeaveNil: true, }) require.Nil(t, err) require.Nil(t, conf.MySQL) }
func TestNestedUnexportedField(t *testing.T) { var conf struct { Foo struct { Bar struct { baz string } } } os.Setenv("FOO_BAR_BAZ", "foobar") err := envconfig.Init(&conf) require.Equal(t, envconfig.ErrUnexportedField, err) err = envconfig.InitWithOptions(&conf, envconfig.Options{AllowUnexported: true}) require.Equal(t, nil, err) }