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