Skip to content
Permalink
Browse files

Fixing find

  • Loading branch information...
Depado committed Oct 24, 2018
1 parent d76931b commit 4235a79ef81e14054a79d7a909dd6225f1b0ddad
Showing with 10 additions and 0 deletions.
  1. +9 −0 conf/variables.go
  2. +1 −0 conf/variables_test.go
@@ -15,11 +15,20 @@ type Variables []*Variable
// FindNamed will find a variable by name in the global variables. Returns nil
// if not found
func (vv Variables) FindNamed(s string) *Variable {
// First pass, top level
for _, v := range vv {
if v.Name == s {
return v
}
}
// Second pass, get inside variables
for _, v := range vv {
if v.Variables != nil {
if out := v.Variables.FindNamed(s); out != nil {
return out
}
}
}
return nil
}

@@ -90,6 +90,7 @@ func TestVariables_FindNamed(t *testing.T) {
{"should find bool", vv, args{hasbool.Name}, hasbool},
{"should find value", vv, args{hasvalue.Name}, hasvalue},
{"shouldn't find", vv, args{"random.jpg"}, nil},
{"should find nested", Variables{parentvar}, args{"sub"}, subvar},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {

0 comments on commit 4235a79

Please sign in to comment.
You can’t perform that action at this time.