From 335f5bc5e4c4e4663f44ea0f7ea1429e47194d11 Mon Sep 17 00:00:00 2001 From: Aaron Birkland Date: Fri, 3 May 2019 16:34:39 -0400 Subject: [PATCH] Remove unnecessary error condition Failure match ${x.y.z} in ${x.y.z.q} should not be an error, it should simply result in no values. --- rule/context.go | 4 ---- rule/context_test.go | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/rule/context.go b/rule/context.go index 4b2f90b..9016188 100644 --- a/rule/context.go +++ b/rule/context.go @@ -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} diff --git a/rule/context_test.go b/rule/context_test.go index 6b041f9..0987bb0 100644 --- a/rule/context_test.go +++ b/rule/context_test.go @@ -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 {