Skip to content

Commit

Permalink
Add support for getting resources with dots
Browse files Browse the repository at this point in the history
Signed-off-by: twobiers <[email protected]>
twobiers committed Nov 12, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 7d8d2d2 commit 5d7b83d
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion function_maps.go
Original file line number Diff line number Diff line change
@@ -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
}
16 changes: 16 additions & 0 deletions function_maps_test.go
Original file line number Diff line number Diff line change
@@ -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{

0 comments on commit 5d7b83d

Please sign in to comment.