fix(config/env): prefixs typo (#2321)

pull/2349/head
icylight 2 years ago committed by GitHub
parent ad7597c0b1
commit 60b00c8ade
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      config/env/env.go
  2. 20
      config/env/env_test.go

10
config/env/env.go vendored

@ -8,11 +8,11 @@ import (
)
type env struct {
prefixs []string
prefixes []string
}
func NewSource(prefixs ...string) config.Source {
return &env{prefixs: prefixs}
func NewSource(prefixes ...string) config.Source {
return &env{prefixes: prefixes}
}
func (e *env) Load() (kv []*config.KeyValue, err error) {
@ -29,8 +29,8 @@ func (e *env) load(envStrings []string) []*config.KeyValue {
v = subs[1]
}
if len(e.prefixs) > 0 {
p, ok := matchPrefix(e.prefixs, k)
if len(e.prefixes) > 0 {
p, ok := matchPrefix(e.prefixes, k)
if !ok || len(p) == len(k) {
continue
}

@ -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)

Loading…
Cancel
Save