From 08667e769ed1e8d300a01d66744b71d346b288ea Mon Sep 17 00:00:00 2001 From: Gordon Date: Thu, 29 Feb 2024 11:52:48 -0500 Subject: [PATCH] Use prefix instead of equal to handle 'resource(matcher)' types --- pkg/engine/operational_eval/vertex_path_expand.go | 2 +- .../operational_eval/vertex_path_expand_test.go | 1 + .../properties/string_property_test.go | 14 ++++++++++++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/pkg/engine/operational_eval/vertex_path_expand.go b/pkg/engine/operational_eval/vertex_path_expand.go index 6408df764..451251d6f 100644 --- a/pkg/engine/operational_eval/vertex_path_expand.go +++ b/pkg/engine/operational_eval/vertex_path_expand.go @@ -136,7 +136,7 @@ func (v *pathExpandVertex) addDepsFromProps( var errs error for k, prop := range tmpl.Properties { // Only consider properties whose type can even accommodate a resource - if prop.Type() != "resource" { + if !strings.HasPrefix(prop.Type(), "resource") { continue } details := prop.Details() diff --git a/pkg/engine/operational_eval/vertex_path_expand_test.go b/pkg/engine/operational_eval/vertex_path_expand_test.go index 4a0a8ed2c..11f794618 100644 --- a/pkg/engine/operational_eval/vertex_path_expand_test.go +++ b/pkg/engine/operational_eval/vertex_path_expand_test.go @@ -154,6 +154,7 @@ func Test_pathExpandVertex_addDepsFromProps(t *testing.T) { mockSol.On("RawView").Return(resultGraph).Once() mockProperty.EXPECT().Validate(resource, construct.ResourceId{Name: "u"}, gomock.Any()).Return(nil).Times(1) + mockProperty.EXPECT().Type().Return("resource").Times(1) return nil }, want: graphChanges{ diff --git a/pkg/knowledgebase/properties/string_property_test.go b/pkg/knowledgebase/properties/string_property_test.go index 68f3af66e..dec95514c 100644 --- a/pkg/knowledgebase/properties/string_property_test.go +++ b/pkg/knowledgebase/properties/string_property_test.go @@ -235,13 +235,23 @@ func Test_StringParse(t *testing.T) { expected: "test", }, { - name: "non string throws error", + name: "non string converts int", + property: &StringProperty{ + PropertyDetails: knowledgebase.PropertyDetails{ + Path: "test", + }, + }, + value: 1, + expected: "1", + }, + { + name: "non string fails non-primitive", property: &StringProperty{ PropertyDetails: knowledgebase.PropertyDetails{ Path: "test", }, }, - value: 1, + value: []string{"hi"}, wantErr: true, }, }