Skip to content

Commit

Permalink
Fixing find
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Lhussiez committed Oct 24, 2018
1 parent d76931b commit 4235a79
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
9 changes: 9 additions & 0 deletions conf/variables.go
Expand Up @@ -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
}

Expand Down
1 change: 1 addition & 0 deletions conf/variables_test.go
Expand Up @@ -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) {
Expand Down

0 comments on commit 4235a79

Please sign in to comment.