make environment variable interpolation preprocessor optional (#1715)

This commit is contained in:
Colin Hoglund
2020-07-06 15:13:35 -04:00
committed by GitHub
parent 97ae2979ad
commit 90dca65f55
5 changed files with 62 additions and 12 deletions

View File

@@ -3,6 +3,7 @@ package json
import (
"testing"
"github.com/micro/go-micro/v2/config/reader"
"github.com/micro/go-micro/v2/config/source"
)
@@ -23,7 +24,46 @@ func TestReader(t *testing.T) {
},
}
r := NewReader()
values := newTestValues(t, data)
for _, test := range testData {
if v := values.Get(test.path...).String(""); v != test.value {
t.Fatalf("Expected %s got %s for path %v", test.value, v, test.path)
}
}
}
func TestDisableReplaceEnvVars(t *testing.T) {
data := []byte(`{"foo": "bar", "baz": {"bar": "test/${test}"}}`)
tests := []struct {
path []string
value string
opts []reader.Option
}{
{
[]string{"baz", "bar"},
"test/",
nil,
},
{
[]string{"baz", "bar"},
"test/${test}",
[]reader.Option{reader.WithDisableReplaceEnvVars()},
},
}
for _, test := range tests {
values := newTestValues(t, data, test.opts...)
if v := values.Get(test.path...).String(""); v != test.value {
t.Fatalf("Expected %s got %s for path %v", test.value, v, test.path)
}
}
}
func newTestValues(t *testing.T, data []byte, opts ...reader.Option) reader.Values {
r := NewReader(opts...)
c, err := r.Merge(&source.ChangeSet{Data: data}, &source.ChangeSet{})
if err != nil {
@@ -35,9 +75,5 @@ func TestReader(t *testing.T) {
t.Fatal(err)
}
for _, test := range testData {
if v := values.Get(test.path...).String(""); v != test.value {
t.Fatalf("Expected %s got %s for path %v", test.value, v, test.path)
}
}
return values
}