git.iko.soy/typeable/oauth2-proxy
on v5.1.0 help sign in
typeable/oauth2-proxy/env_options_test.go
46 lines 976 B history raw
1package main_test
3import (
4 "os"
5 "testing"
7 proxy "github.com/pusher/oauth2_proxy"
8 "github.com/stretchr/testify/assert"
9)
11type EnvTest struct {
12 TestField string `cfg:"target_field" env:"TEST_ENV_FIELD"`
13 EnvTestEmbed
16type EnvTestEmbed struct {
17 TestFieldEmbed string `cfg:"target_field_embed" env:"TEST_ENV_FIELD_EMBED"`
20func TestLoadEnvForStruct(t *testing.T) {
22 cfg := make(proxy.EnvOptions)
23 cfg.LoadEnvForStruct(&EnvTest{})
25 _, ok := cfg["target_field"]
26 assert.Equal(t, ok, false)
28 os.Setenv("TEST_ENV_FIELD", "1234abcd")
29 cfg.LoadEnvForStruct(&EnvTest{})
30 v := cfg["target_field"]
31 assert.Equal(t, v, "1234abcd")
34func TestLoadEnvForStructWithEmbeddedFields(t *testing.T) {
36 cfg := make(proxy.EnvOptions)
37 cfg.LoadEnvForStruct(&EnvTest{})
39 _, ok := cfg["target_field_embed"]
40 assert.Equal(t, ok, false)
42 os.Setenv("TEST_ENV_FIELD_EMBED", "1234abcd")
43 cfg.LoadEnvForStruct(&EnvTest{})
44 v := cfg["target_field_embed"]
45 assert.Equal(t, v, "1234abcd")