From 5d7b83dcb8077e6e72b35febc9988032f0f1f349 Mon Sep 17 00:00:00 2001 From: twobiers <22715034+twobiers@users.noreply.github.com> Date: Tue, 12 Nov 2024 15:49:21 +0100 Subject: [PATCH] Add support for getting resources with dots Signed-off-by: twobiers <22715034+twobiers@users.noreply.github.com> --- function_maps.go | 2 +- function_maps_test.go | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/function_maps.go b/function_maps.go index 4dff6ea..f4deb5b 100644 --- a/function_maps.go +++ b/function_maps.go @@ -114,7 +114,7 @@ func initInclude(t *template.Template) func(string, interface{}) (string, error) func getComposedResource(req map[string]any, name string) map[string]any { var cr map[string]any - path := fmt.Sprintf("observed.resources.%s.resource", name) + path := fmt.Sprintf("observed.resources[%s]resource", name) if err := fieldpath.Pave(req).GetValueInto(path, &cr); err != nil { return nil } diff --git a/function_maps_test.go b/function_maps_test.go index 8767755..ef3777f 100644 --- a/function_maps_test.go +++ b/function_maps_test.go @@ -375,6 +375,22 @@ func Test_getComposedResource(t *testing.T) { }, want: want{rsp: completeResource}, }, + "RetrieveCompleteResourceWithDots": { + reason: "Should successfully retrieve the complete resource when identifier contains dots", + args: args{ + req: map[string]any{ + "observed": map[string]any{ + "resources": map[string]any{ + "flex.server": map[string]any{ + "resource": completeResource, + }, + }, + }, + }, + name: "flex.server", + }, + want: want{rsp: completeResource}, + }, "ResourceNotFound": { reason: "Should return nil if the resource is not found", args: args{