|
|
|
@ -261,7 +261,7 @@ func TestEnvWithoutPrefix(t *testing.T) { |
|
|
|
|
|
|
|
|
|
func Test_env_load(t *testing.T) { |
|
|
|
|
type fields struct { |
|
|
|
|
prefixs []string |
|
|
|
|
prefixes []string |
|
|
|
|
} |
|
|
|
|
type args struct { |
|
|
|
|
envStrings []string |
|
|
|
@ -275,7 +275,7 @@ func Test_env_load(t *testing.T) { |
|
|
|
|
{ |
|
|
|
|
name: "without prefixes", |
|
|
|
|
fields: fields{ |
|
|
|
|
prefixs: nil, |
|
|
|
|
prefixes: nil, |
|
|
|
|
}, |
|
|
|
|
args: args{ |
|
|
|
|
envStrings: []string{ |
|
|
|
@ -294,7 +294,7 @@ func Test_env_load(t *testing.T) { |
|
|
|
|
{ |
|
|
|
|
name: "empty prefix", |
|
|
|
|
fields: fields{ |
|
|
|
|
prefixs: []string{""}, |
|
|
|
|
prefixes: []string{""}, |
|
|
|
|
}, |
|
|
|
|
args: args{ |
|
|
|
|
envStrings: []string{ |
|
|
|
@ -313,7 +313,7 @@ func Test_env_load(t *testing.T) { |
|
|
|
|
{ |
|
|
|
|
name: "underscore prefix", |
|
|
|
|
fields: fields{ |
|
|
|
|
prefixs: []string{"_"}, |
|
|
|
|
prefixes: []string{"_"}, |
|
|
|
|
}, |
|
|
|
|
args: args{ |
|
|
|
|
envStrings: []string{ |
|
|
|
@ -332,7 +332,7 @@ func Test_env_load(t *testing.T) { |
|
|
|
|
{ |
|
|
|
|
name: "with prefixes", |
|
|
|
|
fields: fields{ |
|
|
|
|
prefixs: []string{"KRATOS_", "FOO"}, |
|
|
|
|
prefixes: []string{"KRATOS_", "FOO"}, |
|
|
|
|
}, |
|
|
|
|
args: args{ |
|
|
|
|
envStrings: []string{ |
|
|
|
@ -351,7 +351,7 @@ func Test_env_load(t *testing.T) { |
|
|
|
|
{ |
|
|
|
|
name: "should not panic #1", |
|
|
|
|
fields: fields{ |
|
|
|
|
prefixs: []string{"FOO"}, |
|
|
|
|
prefixes: []string{"FOO"}, |
|
|
|
|
}, |
|
|
|
|
args: args{ |
|
|
|
|
envStrings: []string{ |
|
|
|
@ -364,7 +364,7 @@ func Test_env_load(t *testing.T) { |
|
|
|
|
{ |
|
|
|
|
name: "should not panic #2", |
|
|
|
|
fields: fields{ |
|
|
|
|
prefixs: []string{"FOO=1"}, |
|
|
|
|
prefixes: []string{"FOO=1"}, |
|
|
|
|
}, |
|
|
|
|
args: args{ |
|
|
|
|
envStrings: []string{ |
|
|
|
@ -377,7 +377,7 @@ func Test_env_load(t *testing.T) { |
|
|
|
|
for _, tt := range tests { |
|
|
|
|
t.Run(tt.name, func(t *testing.T) { |
|
|
|
|
e := &env{ |
|
|
|
|
prefixs: tt.fields.prefixs, |
|
|
|
|
prefixes: tt.fields.prefixes, |
|
|
|
|
} |
|
|
|
|
got := e.load(tt.args.envStrings) |
|
|
|
|
if !reflect.DeepEqual(tt.want, got) { |
|
|
|
@ -419,8 +419,8 @@ func Test_matchPrefix(t *testing.T) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func Test_env_watch(t *testing.T) { |
|
|
|
|
prefixs := []string{"BAR", "FOO"} |
|
|
|
|
source := NewSource(prefixs...) |
|
|
|
|
prefixes := []string{"BAR", "FOO"} |
|
|
|
|
source := NewSource(prefixes...) |
|
|
|
|
w, err := source.Watch() |
|
|
|
|
if err != nil { |
|
|
|
|
t.Errorf("expect no err, got %v", err) |
|
|
|
|