You've already forked oauth2-proxy
mirror of
https://github.com/oauth2-proxy/oauth2-proxy.git
synced 2025-07-13 01:40:48 +02:00
Allow embedded structs in env_options
This commit is contained in:
@ -1,26 +1,46 @@
|
||||
package main
|
||||
package main_test
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
proxy "github.com/pusher/oauth2_proxy"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
type envTest struct {
|
||||
testField string `cfg:"target_field" env:"TEST_ENV_FIELD"`
|
||||
type EnvTest struct {
|
||||
TestField string `cfg:"target_field" env:"TEST_ENV_FIELD"`
|
||||
EnvTestEmbed
|
||||
}
|
||||
|
||||
type EnvTestEmbed struct {
|
||||
TestFieldEmbed string `cfg:"target_field_embed" env:"TEST_ENV_FIELD_EMBED"`
|
||||
}
|
||||
|
||||
func TestLoadEnvForStruct(t *testing.T) {
|
||||
|
||||
cfg := make(EnvOptions)
|
||||
cfg.LoadEnvForStruct(&envTest{})
|
||||
cfg := make(proxy.EnvOptions)
|
||||
cfg.LoadEnvForStruct(&EnvTest{})
|
||||
|
||||
_, ok := cfg["target_field"]
|
||||
assert.Equal(t, ok, false)
|
||||
|
||||
os.Setenv("TEST_ENV_FIELD", "1234abcd")
|
||||
cfg.LoadEnvForStruct(&envTest{})
|
||||
cfg.LoadEnvForStruct(&EnvTest{})
|
||||
v := cfg["target_field"]
|
||||
assert.Equal(t, v, "1234abcd")
|
||||
}
|
||||
|
||||
func TestLoadEnvForStructWithEmbeddedFields(t *testing.T) {
|
||||
|
||||
cfg := make(proxy.EnvOptions)
|
||||
cfg.LoadEnvForStruct(&EnvTest{})
|
||||
|
||||
_, ok := cfg["target_field_embed"]
|
||||
assert.Equal(t, ok, false)
|
||||
|
||||
os.Setenv("TEST_ENV_FIELD_EMBED", "1234abcd")
|
||||
cfg.LoadEnvForStruct(&EnvTest{})
|
||||
v := cfg["target_field_embed"]
|
||||
assert.Equal(t, v, "1234abcd")
|
||||
}
|
||||
|
Reference in New Issue
Block a user