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

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

Loading…
Cancel
Save