Skip to content
This repository has been archived by the owner on Nov 30, 2023. It is now read-only.

Commit

Permalink
Remove unnecessary error condition
Browse files Browse the repository at this point in the history
Failure match ${x.y.z} in ${x.y.z.q} should not be an error, it should
simply result in no values.
  • Loading branch information
birkland committed May 3, 2019
1 parent 23f1442 commit 335f5bc
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
4 changes: 0 additions & 4 deletions rule/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,6 @@ func (c *Context) extractValues(v variable, resolvedList []resolvedObject) error
}
}

if len(vals) == 0 {
return errors.Errorf("no values of %s have key %s", v.prev().segmentName, v.segment)
}

c.values[v.segmentName] = vals
c.values[v.segment] = vals // this is the shortcut ${properties}, instead of ${x.y.properties}

Expand Down
42 changes: 42 additions & 0 deletions rule/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,48 @@ func TestContextResolve(t *testing.T) {
}`,
},
expectedValue: []string{"a", "b", "c", "d", "e"},
}, {
testName: "traverse many ist objects no results",
varName: "${submission.foo.bar.rhubarb}",
fetcher: map[string]string{
submissionURI: `{
"foo": [
"http:/example.org/foo/1",
"http:/example.org/foo/2"
]
}`,
"http:/example.org/foo/1": `{
"bar": [
"http:/example.org/bar/1",
"http:/example.org/bar/2"
]
}`,
"http:/example.org/foo/2": `{
"bar": [
"http:/example.org/bar/1",
"http:/example.org/bar/3"
]
}`,
"http:/example.org/bar/1": `{
"nope": [
"a",
"b"
]
}`,
"http:/example.org/bar/2": `{
"nope": [
"b",
"c"
]
}`,
"http:/example.org/bar/3": `{
"nope": [
"d",
"e"
]
}`,
},
expectedValue: []string{},
}}

for _, c := range cases {
Expand Down

0 comments on commit 335f5bc

Please sign in to comment.