mirror of
https://github.com/yusing/godoxy.git
synced 2026-03-29 13:21:55 +02:00
feat(yaml): extend environment variable substitution to all YAML files
- returns error for unset environment variables
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
package serialization
|
||||
|
||||
import (
|
||||
"os"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"testing"
|
||||
|
||||
"github.com/goccy/go-yaml"
|
||||
"github.com/stretchr/testify/require"
|
||||
. "github.com/yusing/go-proxy/internal/utils/testing"
|
||||
)
|
||||
|
||||
@@ -314,6 +316,26 @@ func TestStringToStruct(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestConfigEnvSubstitution(t *testing.T) {
|
||||
os.Setenv("CLOUDFLARE_AUTH_TOKEN", "test")
|
||||
data := []byte(`
|
||||
---
|
||||
autocert:
|
||||
options:
|
||||
auth_token: ${CLOUDFLARE_AUTH_TOKEN}
|
||||
`)
|
||||
|
||||
var cfg struct {
|
||||
Autocert struct {
|
||||
Options struct {
|
||||
AuthToken string `yaml:"auth_token"`
|
||||
} `yaml:"options"`
|
||||
} `yaml:"autocert"`
|
||||
}
|
||||
require.NoError(t, UnmarshalValidateYAML(data, &cfg))
|
||||
require.Equal(t, "test", cfg.Autocert.Options.AuthToken)
|
||||
}
|
||||
|
||||
func BenchmarkStringToStruct(b *testing.B) {
|
||||
for range b.N {
|
||||
dst := struct {
|
||||
|
||||
Reference in New Issue
Block a user